重置 jQuery Accordion
我在一页上有两个手风琴。 我希望这样当单击/激活一个手风琴时,另一个手风琴(如果打开)将返回到其默认的折叠状态。
我尝试手动重新创建该功能,但它的问题太多,最终不允许我扩展手风琴。
我的代码:
$('#chicago-accordion').accordion({ autoHeight: false, collapsible: true, active:false, });
$('#chicago-accordion h2').click(function () {
$('#ny-accordion .accordion-content').slideUp();
$('#ny-accordion h2').removeClass("ui-state-active");
$('#ny-accordion .accordion-content').removeClass("ui-accordion-content-active");
$('#ny-accordion').accordion({ clearStyle:true, });
});
$('#ny-accordion').accordion({ autoHeight: false, collapsible: true, active:false, });
$('#ny-accordion h2').click(function () {
$('#chicago-accordion .accordion-content').slideUp();
$('#chicago-accordion .accordion-content').removeClass("ui-accordion-content-active");
$('#chicago-accordion h2').removeClass("ui-state-active");
$('#chicago-accordion').accordion({ clearStyle:true, });
});
});
I have two accordions on one page. I would like it so that when one is clicked/activated the other accordion (if opened) will return to its default folded state.
I have tried to manually recreate the functionality but it is too buggy and eventually doesn't let me expand accordions.
My code:
$('#chicago-accordion').accordion({ autoHeight: false, collapsible: true, active:false, });
$('#chicago-accordion h2').click(function () {
$('#ny-accordion .accordion-content').slideUp();
$('#ny-accordion h2').removeClass("ui-state-active");
$('#ny-accordion .accordion-content').removeClass("ui-accordion-content-active");
$('#ny-accordion').accordion({ clearStyle:true, });
});
$('#ny-accordion').accordion({ autoHeight: false, collapsible: true, active:false, });
$('#ny-accordion h2').click(function () {
$('#chicago-accordion .accordion-content').slideUp();
$('#chicago-accordion .accordion-content').removeClass("ui-accordion-content-active");
$('#chicago-accordion h2').removeClass("ui-state-active");
$('#chicago-accordion').accordion({ clearStyle:true, });
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我找到的解决该问题的简单方法是销毁并重新创建手风琴。
The simplies solution I have found for that problem is to destroy and recreate the accordion.
这是我用来重置单个手风琴的方法:
要重置特定的,您可以使用
Here's what I use to reset an single accordion:
To reset specific ones, you can use
这将重置您的手风琴,且没有选定的选项卡。
通过 addClass/removeClass/attr 进行重置将使您的手风琴在视觉上看起来不错,但需要单击 2 次才能激活先前选择的选项卡。
谢谢
This will reset your accordion with no selected tab.
Resetting through addClass/removeClass/attr will make your accordion looks good visually but it requires 2 clicks to activate previous selected tab.
Thanks