通过事件触发jQuery手风琴菜单? [英] Trigger jquery accordion menu by an event?
本文介绍了通过事件触发jQuery手风琴菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以通过单独的按钮onclick事件在jQuery手风琴菜单中打开下一个面板?那不是单击标题打开另一个面板,而是使用未连接到手风琴的按钮.
Is it possible to open the next panel in a jquery accordion menu through a seperate button onclick event? That is instead of clicking the heading to open another panel, use a button not connected to the accordion.
推荐答案
是的,只需像这样在手风琴上调用activate
:
Yes, just call activate
on the accordion like this:
$("#myaccordion").accordion("activate", 1 );
1
是要打开的索引.
您可以通过调用以下内容获取活动面板的当前从零开始的索引:
You can get the current zero-based index of the active panel by calling:
var index = $("#myaccordion").accordion('option','active');
因此,将这两个项目放在一起,我们可以通过单击打开下一个项目:
So, taking both these items together, we can open the next item on a click:
$("#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);
})
这篇关于通过事件触发jQuery手风琴菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文