2010-06-12 25 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); 

}