2010-06-12 26 views

回答

13

是的,只需撥打這樣的手風琴activate

$("#myaccordion").accordion("activate", 1); 

哪裏1是要打開的索引。

你可以通過調用得到活動面板的電流從零開始的索引:

var index = $("#myaccordion").accordion('option','active'); 

所以,服用這兩種物品放在一起,我們可以打開上的點擊下一個項目:

$("#mybutton").click(function(e){ 
    e.preventDefault(); 
    var acc = $("#myaccordion"), 
     index = acc.accordion('option','active'), 
     total = acc.children('div').length, 
     nxt = index + 1; 

    if (nxt >= total) { 
    nxt = 0; // Loop around to the first item 
    } 

    acc.accordion('activate', nxt); 
}) 
10

在JQuery UI 1.10或更高版本中,.activate函數已被棄用,以支持使用'option'方法,因此使用上述答案的另一種方法是:

$("#button").click(function(){ 
    var index = $("#accordion").accordion('option','active'); 
    var total = $("#accordion").children('div').length; 
    index++; 

    // include restart same as previous answer  
    if (index >= total) { 
     index = 0; 
    } 

    $("#accordion").accordion("option", "active", index); 

}