use*_*398 10 javascript jquery twitter-bootstrap
我正在选中时突出显示一个表格行,但在其中一个单元格中我有一个按钮.当我单击按钮时,我触发了表行单击事件.有可能将两者分开吗?
我的两个电话目前看起来像这样:
$('table.table-striped tbody tr').on('click', function () {
$(this).find('td').toggleClass('row_highlight_css');
});
$(".email-user").click(function(e) {
e.preventDefault();
alert("Button Clicked");
});
Run Code Online (Sandbox Code Playgroud)
我的HTML看起来像这样:
<table class="table table-bordered table-condensed table-striped">
<thead>
<tr>
<th>col-1</th>
<th>col-2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Some Data</td>
<td><button class="btn btn-mini btn-success email-user" id="email_123" type="button">Email User</button></td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
知道如何阻止按钮点击事件触发行点击事件吗?
Sam*_*rie 16
你必须使用stopPropagation:
$(".email-user").click(function(e) {
e.preventDefault();
e.stopPropagation();
alert("Button Clicked");
});
Run Code Online (Sandbox Code Playgroud)
(另请参阅:event.stopPropagation和event.preventDefault之间有什么区别?)
| 归档时间: |
|
| 查看次数: |
9019 次 |
| 最近记录: |