我有一个表格,其中一行包含一个单元格中的按钮。 <tr>
有一个 onclick 事件。我希望按钮独立于 <tr>
运行onclick 但在同一行内操作。
HTML:
<tr onclick="$trigger();">
<td>Data A</td>
<td>Data B</td>
<td>Data C</td>
<td><button onclick="$buttonClicked();">Submit</button></td>
</tr>
这可能吗?
最佳答案
您可以使用 event.stopPropagation() :
Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.
$('button').click(function(event) {
event.stopPropagation();
});
关于javascript - 防止按钮点击激活 <tr> onclick 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22715278/