我有一个完美运行的 Bootstrap Accordion table 。基本上,如果有人单击一行,它会显示更多内容。现在,问题是其中一行包含一个按钮链接,当有人单击该按钮时,它会正确转到该链接,但它也会打开隐藏的行内容。
我如何做到当有人点击按钮时,它不会打开隐藏的行,而只会转到链接?
<table class="table">
<thead>
<th width="20%" class="">Row 1</th>
<th width="20%" class="">Row 2</th>
<th width="20%" class="">Row 3</th>
<th width="20%" class="">Row 4</th>
<th width="20%" class="">Row 5</th>
</thead>
<tbody>
<tr data-toggle="collapse" data-target="#123" class="accordion-toggle">
<td class="">Content 1</td>
<td class="">Content 2</td>
<td class="">Content 3</td>
<td class="">Content 4</td>
<td class=""><a href="http://www.url.com/" type="button" class="btn btn-primary">Link</a></td>
</tr><tr>
<td colspan="5" class="hiddenRow"><div class="accordian-body collapse" id="123">More Content</div> </td>
</tr>
</tbody>
</table>
最佳答案
尝试这样的事情:-
<a href="http://www.url.com/" onclick= stopEventPropogation(event) type="button" class="btn btn-primary">Link</a>
<script type="text/javascript">
function stopEventPropogation(e){
e.stopPropogation()
}
</script>
或者按照 Bart 的建议,这也可以使用:-
$('.accordion-toggole').on('click', '.btn', function(e) { e.stopPropagation(); })
关于javascript - Bootstrap Accordion 表内带有链接的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27560661/