卷起嵌套 jQuery Accordion 中的子元素
当使用 jQuery 的 Accordion(以嵌套方式)时,我想确保当单击/打开父元素时,所有打开的子元素都会被关闭/卷起。我不确定尝试执行此操作时应该使用什么选择器。到目前为止,我已经尝试将“activate”设置为 false 来操纵更改事件,但这只会使任何打开的元素自动关闭。
假设我只有 1 个嵌套手风琴,我的 jquery 初始化如下所示:
$(".accordion").accordion({
active: false, collapsible: true, autoHeight: false, animated: 'swing'
});
$(".child-accordion").accordion({
active: false, collapsible: true, autoHeight: false, animated: 'swing',
change: function(event, ui) { $(".child-accordion").accordion("activate", false); }
});
其中 .child-accordion 是嵌套实例。当 .accordion 的成员打开时,我需要关闭 .child-accordion 下的任何内容。
When using jQuery's Accordion (in a nested fashion), I want to ensure that when a parent element is clicked/opened, any open children are closed/rolled up. I'm not sure what selector(s) I should use when attempting to do this. So far I've tried rigging a change event with "activate" set to false, but that simply makes any element that is opened automatically close.
Assuming I only have 1 nested accordion, my jquery initialization looks like:
$(".accordion").accordion({
active: false, collapsible: true, autoHeight: false, animated: 'swing'
});
$(".child-accordion").accordion({
active: false, collapsible: true, autoHeight: false, animated: 'swing',
change: function(event, ui) { $(".child-accordion").accordion("activate", false); }
});
where .child-accordion is the nested instance. I need anything under the .child-accordion to be closed when a member of the .accordion is opened.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的版本无法正常工作的原因有两个
您的更改事件需要在父级上,因为那时您希望子级滚动
您需要创建事件
changestart
因为当您将activate
设置为 false 时,它所做的主要事情是切换子级中当前“可见”的部分,但是当父级上触发
change
事件时,子级已经隐藏,因此它不会执行任何操作。编辑:这是此 http://jsfiddle.net/ryleyb/YPpEn 的工作版本/
The reason your version wasn't working is two-fold
Your change event needs to be on the parent, because that's when you want the children to roll up
You need to make the event
changestart
because when you setactivate
to false, the main thing it does istoggle
the currently "visible" section in the child, but when thechange
event triggers on the parent, the child is already hidden, so it doesn't do anything.EDIT: here's a working version of this http://jsfiddle.net/ryleyb/YPpEn/