2011-05-18 55 views
0

我已經使用Soh Tanaka的Simple Accordion tutorial成功構建了一個JQuery手風琴。我希望能夠從另一頁面鏈接到特定的手風琴部分,但我不知道如何做到這一點。任何幫助將不勝感激,因爲我沒有多少運氣找到任何特定於本教程的幫助。謝謝!如何鏈接到不同頁面的特定手風琴部分?

HTML:

<h2 class="acc_trigger"><a href="#">Web Design &amp; Development</a></h2> 
<div class="acc_container"> 
<div class="block"> 
<!--Content Goes Here--> 
</div> 
</div> 

JQuery的:

//Set default open/close settings 
$('.acc_container').hide(); //Hide/close all containers 
$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container 

//On Click 
$('.acc_trigger').click(function(){ 
if($(this).next().is(':hidden')) { //If immediate next container is closed... 
    $('.acc_trigger').removeClass('active').next().slideUp(); //Remove all "active" state and slide up the immediate next container 
    $(this).toggleClass('active').next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container 
} 
return false; //Prevent the browser jump to the link anchor 
}); 

回答

0

你真的應該使用JQuery UI accordion。然後,如果你想要的是能夠通過腳本來選擇特定的手風琴部分,你可以使用以下命令:

$('#myAccordion').accordion("option", "active", 0) 

有了這個代碼,一旦你創造建立在一個標籤ID爲「myAccordion」手風琴元素,您選擇第一頁(即,索引爲0)。要選擇第二頁,您可以爲最後一個參數傳遞1,依此類推。

+0

謝謝 - 我會記住JQuery UI版本! – Lisa 2011-05-19 08:22:12