Jquery 通过参数化css选择器查找元素

Jquery 通过参数化css选择器查找元素,jquery,elementname,Jquery,Elementname,我正在用jQuery构建一个包含多个超链接的菜单,我想在单击超链接时显示/隐藏一个包含子菜单的div 我尝试了以下方法: $("div#divmnu" + mnuidx).show(); $("div#divmnu" + mnuidx).animate({ height: '300px' }, 300); 但它不起作用 有人能帮我吗?这个功能: <html> <head> <title>JQuery Show/Hide w/ Animate</titl

我正在用jQuery构建一个包含多个超链接的菜单,我想在单击超链接时显示/隐藏一个包含子菜单的div

我尝试了以下方法:

$("div#divmnu" + mnuidx).show();
$("div#divmnu" + mnuidx).animate({ height: '300px' }, 300);
但它不起作用

有人能帮我吗?

这个功能:

<html>
<head>
<title>JQuery Show/Hide w/ Animate</title>
<script src="js/jquery-1.8.2.js"></script>
<script src="js/jquery-ui.js"></script>
<script>
    function show(button) {
        var idx = button.attr("id").substring(1);
        $("div#menu" + idx).show();
        $("div#menu" + idx).animate({ height: '300px' }, 300);
    }
    function hide(button) {
        var idx = button.attr("id").substring(1);
        $("div#menu" + idx).animate({ height: '20px' }, 300, "swing", function() { $("div#menu" + idx).hide(); });
    }
    $(document).ready(function() {
        $("div#menu1").hide();
        $("div#menu2").hide();
        $("#s1").click(function() { show($(this)); });
        $("#s2").click(function() { show($(this)); });
        $("#h1").click(function() { hide($(this)); });
        $("#h2").click(function() { hide($(this)); });
    });
</script>
</head>
<body>
<div id="menu1" style="font-size: xx-large;">Menu 1</div>
<div id="menu2" style="font-size: xx-large;">Menu 2</div>
<div><button id="s1">Show 1</button><button id="s2">Show 2</button>
     <button id="h1">Hide 1</button><button id="h2">Hide 2</button></div>
</body>
</html>

JQuery显示/隐藏w/动画
功能显示(按钮){
var idx=button.attr(“id”).子字符串(1);
$(“div#menu”+idx.show();
$(“div#menu”+idx).animate({height:'300px'},300);
}
功能隐藏(按钮){
var idx=button.attr(“id”).子字符串(1);
$(“div#menu”+idx).animate({height:'20px'},300,“swing”,function(){$(“div#menu”+idx.hide();});
}
$(文档).ready(函数(){
$(“div#menu1”).hide();
$(“div#menu2”).hide();
$(“#s1”)。单击(函数(){show($(this));});
$(“#s2”)。单击(函数(){show($(this));});
$(“#h1”)。单击(函数(){hide($(this));});
$(“#h2”)。单击(函数(){hide($(this));});
});
菜单1
菜单2
展示1展示2
隐藏1隐藏2

请也共享您的HTML?