简体   繁体   English

Bootstrap 2或Bootstrap 3如何折叠手风琴

[英]Bootstrap 2 or Bootstrap 3 how to collapse open accordion

I am building own accordion markup by using bootstrap collapse 我正在使用Bootstrap折叠构建自己的手风琴标记

Does anyone know how to close the open accordion when you click on any other? 当您单击任何其他手风琴时,有人知道如何关闭打开的手风琴吗?

I tried with 我尝试过

        //bs2
        $('#top1_accordion').on('show','.collapse', function() {
            $('#top1_accordion').find('.collapse.in').collapse('hide');
        }); 
        //bs3
        $('#top1_accordion').on('show.bs.collapse','.collapse', function() {
            $('#top1_accordion').find('.collapse.in').collapse('hide');
        }); 

bootstrap 3 works on first click only http://jsfiddle.net/4WsFK/1/ bootstrap 3仅在首次单击时起作用http://jsfiddle.net/4WsFK/1/

I got it working on bootstrap 2 我在bootstrap 2上工作

http://jsfiddle.net/MTKp7/26/ http://jsfiddle.net/MTKp7/26/

Any help is appreciated! 任何帮助表示赞赏!

I believe the this fiddle should work. 我相信这个小提琴应该起作用。 I only removed the class 'collapse' from your find statement. 我只从您的find语句中删除了“崩溃”类。 I'm not sure of all differences in 3.0, but they must've changed the markup slightly. 我不确定3.0中的所有差异,但是它们必须对标记进行了些微更改。

$('#top1_accordion').find('in').collapse('hide');

http://jsfiddle.net/9jZDE/1/ http://jsfiddle.net/9jZDE/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM