2013-04-21 140 views
1

我是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選擇器代替它,它的工作原理是:(

回答

2

嘗試從這個替換您的代碼onclick屬性:

onclick="showContent(startPageContent, 394)" 

這樣:

onclick="showContent('startPageContent', 394)" 

,然後再試一次..