简体   繁体   English

带有Bootstrap手风琴表内链接的按钮

[英]Button with link inside Bootstrap accordion table

I have a Bootstrap accordion table that works perfectly. 我有一个可以完美运行的Bootstrap手风琴表。 Basically, it shows more content if someone clicks a row. 基本上,如果有人点击一行,它会显示更多内容。 Now, the problem is that one of the rows contains a button link and when someone clicks that button, it goes to that link correctly, but it also opens the hidden row content. 现在,问题是其中一行包含一个按钮链接,当有人点击该按钮时,它会正确地转到该链接,但它也会打开隐藏的行内容。

How do I make it so that when someone clicks on the button, it doesn't open the hidden row as well and goes to the link only? 如何制作它,以便当有人点击按钮时,它也不会打开隐藏的行并仅转到链接?

<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>

Try something like this:- 尝试这样的事情: -

<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>

OR as suggested by Bart this can also be used:- 或者按照Bart的建议,也可以使用: -

$('.accordion-toggole').on('click', '.btn', function(e) { e.stopPropagation(); })

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

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