[英]jQuery Accordion expand first enabled panel
I am using a jQuery Accordion but I have a small problem: Based on some conditions, my accordion could have the first enabled H3 to be the second or third one. 我正在使用jQuery手风琴,但是有一个小问题:在某些情况下,我的手风琴可以将第一个启用的H3设置为第二个或第三个。 The first ones I am disabling by adding this class to them "ui-state-disabled".
我通过将此类添加到“ ui-state-disabled”来禁用它们。
My accordion looks like this: 我的手风琴看起来像这样:
$("#accordion").accordion({
active: true,
animate: false,
collapsible: true,
heightStyle: "content",
icons: icons
});
Is there a way so that the accordion will only expand the first enabled section? 有没有办法让手风琴只扩展第一个启用的部分? Right now, if I put active: 0 and the first element is disabled, it will expand it nonetheless.
现在,如果我将active设置为0,并且第一个元素被禁用,它将仍然对其进行扩展。
Any suggestions ? 有什么建议么 ?
This may not be the most elegant of solutions, but it'll work. 这可能不是最优雅的解决方案,但它会起作用。 You need to find the index of the first
H3
inside the #accordion
element that does not have the class .ui-state-disabled
... so here's that. 您需要在
#accordion
元素内找到第一个H3
的索引,该元素没有类.ui-state-disabled
...就是这样。
You may also realize this already, but you'll want to remove the ability to click to open disabled sections, so I threw that in. 您可能也已经意识到这一点,但是您将想要取消单击以打开禁用的部分的功能,因此我将其介绍了一下。
$("#accordion").accordion({
active: $('h3:not(.ui-state-disabled):first').index('#accordion h3'),
animate: false,
collapsible: true,
heightStyle: "content",
icons: icons
});
$(".ui-state-disabled").unbind("click");
edited to add back in your icons: icons
编辑以添加回您的
icons: icons
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.