javascript - Bootstrap Accordion 表内带有链接的按钮

标签 javascript jquery html twitter-bootstrap

我有一个完美运行的 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/

相关文章:

javascript - 删除标记谷歌地图不起作用 API v3

javascript - ajax表单提交不起作用

javascript - 获取 html 表单信息并使用 ajax 推送到 PHP

php - UIDatePicker - 来自 php Var 的 minDate 和 maxDate

php - AJAX 数组与 MySQL 表交互时出现问题

jquery - 溢出时路点无法工作 :hidden;

html - <1px 边框问题在 Safari 11.1.2

html - 在链接中包装 block 级元素的 SEO 效果

javascript - 从 Instruments Javascript 代码访问 native IOS 功能

javascript - 如何通过滚动更改导航栏背景?