0

有这个让我难以置信的问题。我在手风琴组中有一个复选框。我的程序是当按下手风琴组内的复选框时,它会扩展该手风琴组的主体,并在show()其他地方扩展另一个按钮。

问题是当按下两个复选框时,按钮会很快显示和隐藏。我的假设是点击事件在某处冒泡,我无法在那里抓住它并永远关闭它!

我的 HTML

<div class="accordion span5" id="info-accordion">
    <div class="accordion-group" data-pid="71" data-pweight="2">
        <div class="accordion-heading">
            <input type="checkbox" class="tier-check" value="17">
            <a class="accordion-toggle" data-toggle="collapse" href="#collapse-17">2013-07-10 14:21:03</a>
        </div>
        <div id="collapse-17" class="accordion-body in collapse" style="height: auto;">
            <div class="accordion-inner">Naware is a village in the Bassar Prefecture in the Kara Region of north-western Togo. and add some more content. This is the old one. should show in the info now. To be save really.

            This text should be improved.
            </div>
        </div>
    </div>
    <div class="accordion-group" data-pid="71" data-pweight="2">
        <div class="accordion-heading">
            <input type="checkbox" class="tier-check" value="21">
                <a class="accordion-toggle" data-toggle="collapse" href="#collapse-21">2013-07-10 14:20:39</a>
        </div>
        <div id="collapse-21" class="accordion-body in collapse" style="height: auto;">
            <div class="accordion-inner">Naware is a village in the Bassar Prefecture in the Kara Region of north-western Togo. and add some more content. This is the old one. should show in the info now. To be save really.

            This text should be improved.


            This is new text
            </div>
        </div>
    </div>
    <div class="accordion-group" data-pid="71" data-pweight="2">
        <div class="accordion-heading">
            <input type="checkbox" class="tier-check" value="18">
            <a class="accordion-toggle" data-toggle="collapse" href="#collapse-18">2013-07-10 14:07:53</a>
        </div>
        <div id="collapse-18" class="accordion-body in collapse" style="height: auto;">
            <div class="accordion-inner">Naware is no more
            </div>
        </div>
    </div>
</div>

我的javascript是

//hide them all
var orgchk = $('.tier-check:checkbox').not(':checked');

orgchk.each(function(i) { 
    $(this).removeAttr('disabled');

    var cllps = $('#collapse-' + $(this).val() ); 
    if ( cllps.hasClass('in') );
            cllps.collapse('toggle');
});

//when only one checkbox is selected, show it
var chkbx = $('.tier-check:checkbox:checked');
$('#collapse-' + chkbx.val() ).collapse('show');

if ( chkbx.length != 0 )
         $tier_btn.fadeIn();
else
         $tier_btn.fadeOut();

这是一个小提琴http://jsfiddle.net/nuE2c/仍然针对我的情况进行定制

4

1 回答 1

0

我通过使用这个找到了解决方案。当 jQuery stopPropogation() 和 StopImmediatePropagation() 对我不起作用时,它似乎停止了事件传播

$('#accordion').on('hidden',function(e) {
            return false;//stopping propagation
    });
于 2013-07-11T03:19:15.217 回答