将参数传递给jQuery选择器
问题描述:
我是JS新手,请耐心等待。我试图将字符串参数传递到jQuery的ID选择,但不知它不工作..将参数传递给jQuery选择器
HTML:
<li id="startPageButton" class="buttons" onclick="showContent(startPageContent, 394)">Startpage</li>
JS:
function showContent(cont, boxHeight) {
$(".content").fadeOut(5, function(){
$("#contentBox").animate({height: boxHeight + "px" }, 400, function(){
$("#" + cont).fadeIn(100);
});
});
}
“$(”#“+ cont)”部分有问题..如果我用一个简单的ID选择器代替它,它的工作原理是:(
答
尝试从这个替换您的代码onclick
属性:
onclick="showContent(startPageContent, 394)"
这样:
onclick="showContent('startPageContent', 394)"
,然后再试一次..