简体   繁体   English

如何通过单击其中的复选框折叠bootstrap手风琴

[英]How to Collapse bootstrap accordion by click check box inside it

I have a Bootstrap Accordion with a check box inside each of the accordion panel. 我有一个Bootstrap手风琴,每个手风琴面板内都有一个复选框。 When I check the checkbox inside of a panel, its parent should collapse and the next panel should open. 当我选中面板内的复选框时,其父级应该折叠,下一个面板应该打开。

I am using the jQuery icheck plugin for styling checkboxes. 我使用jQuery icheck插件来设置样式复选框。 So what I can do to make the accordion panels collapse? 那么我能做些什么才能让手风琴面板坍塌? FIDDLE 小提琴

$('.item1').on('ifChecked', function(event){

});

If I understood you correctly, you might want something like that: 如果我理解正确,你可能想要这样的东西:

Updated code: 更新的代码:

// Toggle
$('.item1').on('ifChecked', function(event){
    $("#collapseOne").collapse("hide");
});
$('.item2').on('ifChecked', function(event){
    $("#collapseTwo").collapse("hide");
});
$('.item3').on('ifChecked', function(event){
    $("#collapseThree").collapse("hide");
});

$("#collapseOne").on("hidden.bs.collapse", function(e){
    $("#collapseTwo").collapse("show");
});
$("#collapseTwo").on("hidden.bs.collapse", function(e){
    $("#collapseThree").collapse("show");
});
$("#collapseThree").on("hidden.bs.collapse", function(e){
    $("#collapseOne").collapse("show");
});

First fiddle here: http://jsfiddle.net/sap1ruq2/1/ 第一个小提琴: http//jsfiddle.net/sap1ruq2/1/

UPDATED fiddle here: http://jsfiddle.net/bstjmdLp/ 更新的小提琴: http//jsfiddle.net/bstjmdLp/

Let me know if this was what you needed! 如果这是你需要的,请告诉我!

You could do something like this in your case 在你的情况下你可以做这样的事情

$('input').on('ifChecked', function(event){
    $(this).parents('.panel').first().next().find('.panel-heading a').click();
});

Updated with a fiddle: http://jsfiddle.net/Lq07ysbq/11/ 用小提琴更新: http//jsfiddle.net/Lq07ysbq/11/

Ideally you should use the JS API provided by the plug-in. 理想情况下,您应该使用插件提供的JS API。 In this case, use 'hide' and 'show' options ( http://getbootstrap.com/javascript/#collapse ). 在这种情况下,请使用“隐藏”和“显示”选项( http://getbootstrap.com/javascript/#collapse )。 I've updated your fiddle here: http://jsfiddle.net/catalyst156/Lq07ysbq/13/ 我在这里更新了你的小提琴: http//jsfiddle.net/catalyst156/Lq07ysbq/13/

$('.item1').on('ifChecked', function(event){
    $(this).parents('.panel-collapse').collapse('hide');
    $('#collapseTwo').collapse('show');
});

Off the top of my head, I can't come up with a general solution for opening the next panel so for now, the specific id is used. 在我的脑海中,我无法想出打开下一个面板的一般解决方案,所以现在使用特定的ID。

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

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