[英]Bootstrap: Cancel data-toggle=“collapse” on nested button
I want my panel-collapse to collapse when the panel-heading is clicked but not when the button in the panel-heading is clicked. 我希望在单击面板标题时折叠面板折叠,而不是在单击面板标题中的按钮时折叠。
My code: 我的代码:
<div class="panel panel-default">
<div class="panel-heading clearfix" data-toggle="collapse" href="#collapseBody">
<h4 class="panel-title pull-left" style="padding-top: 7.5px;">Body</h4>
<div class="btn-group pull-right">
<!-- The problematic button -->
<a href="#" class="btn btn-default">Button</a>
</div>
</div>
<div class="panel-collapse collapse in" id="collapseBody">
<div class="panel-body" id="body">
</div>
</div>
</div>
What i've tried: 我试过的
I tried to add 我试图添加
<script>
$('.btn').on('click', function (e) {
e.stopPropagation();
});
</script>
But without any effect. 但是没有任何效果。
Can someone please help out a beginner? 有人可以帮助初学者吗? (:
(:
adeneo gave the golden tip in his comment. adeneo在他的评论中给了金毛。
Fix: 固定:
<script>
$( document ).ready(function() {
$('.btn').on('click', function (e) {
e.stopPropagation();
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.