如何防止嵌套的Bootstrap崩溃元素在父级上触发.show()?

Jo *_*gue 4 javascript jquery jsfiddle twitter-bootstrap

这是我设置的jsfiddle;

http://jsfiddle.net/7LBr5/1/

你会注意到我在父手风琴上有指示箭头,还有一个在手风琴显示和隐藏时切换它们的功能.问题是内部折叠区域(用于隐藏产品详细信息)会触发切换父级箭头的功能.当子进程实际上是折叠时,似乎必须在父崩溃元素上触发.show()事件.

我该如何解决这个问题,以便儿童崩溃不会切换父母的箭头?

这是我的函数的代码;

$('.collapse').on('show', function(){
$(this).parent().find(".icon-chevron-right").removeClass("icon-chevron-right").addClass("icon-chevron-down");}).on('hide', function(){
$(this).parent().find(".icon-chevron-down").removeClass("icon-chevron-down").addClass("icon-chevron-right");});
Run Code Online (Sandbox Code Playgroud)

PSL*_*PSL 12

只需在按钮单击使用时停止事件传播到父级event.stopPropagation,以便在按钮上执行click事件后不会触发手风琴上的click事件.

$thisButton.click(function(e) {
      e.stopPropagation();
//.. Code follows
Run Code Online (Sandbox Code Playgroud)

演示

另外,您不需要在选择器上执行每个绑定click事件,而只需为click事件本身指定选择器

$(".btn-switch").click(function (e) {
    e.stopPropagation();
    var $thisButton = $(this);
    $thisButton.toggleClass("btn-primary btn-danger");
    if ($(this).hasClass('btn-danger')) {
        $thisButton.html('<i class="icon-remove-circle icon-white"></i> Remove');
        $(this).parents('.thumbnail').find('.rental-count').val('1');
        $(this).parents('.thumbnail').find('input').change();
    } else {
        $thisButton.html('<i class="icon-ok-circle icon-white"></i> Add to Quote');
        $(this).parents('.thumbnail').find('input').val('');
        $(this).parents('.thumbnail').find('input').prop('checked', false);
        $(this).parents('.thumbnail').find('input').change();
    }
});
Run Code Online (Sandbox Code Playgroud)