javascript - 如何禁用父元素的onclick元素

标签 javascript jquery html css

我有一张有 tr 的 table

<tr onclick="doprocess1()">
   <td>Some data</td>
   <td>Some data</td>
   <td><button onclick="doprocess2()"</td>  <!--I want to disable the clickevent of the <tr> here -->
</tr>

如何实现?

最佳答案

你需要停止event bubbling .

注意

制作unobtrusive

<tr id="tr1">
   <td>Some data</td>
   <td>Some data</td>
   <td><button id="bt1">Click</button></td>  <!--I want to disable the clickevent of the <tr> here -->
</tr>


$(function(){
    $("#tr1").click(function(){
    });
    $("#bt1").click(function(e){
        e.stopPropagation();
    });
});

关于javascript - 如何禁用父元素的onclick元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4666013/

相关文章:

javascript 使用 getElementById 创建具有属性的对象

javascript - Canvas 。 AngularJS。添加文本和图像

javascript - anchor (链接)在 firefox 中没有鼠标事件,当在绝对框中时

javascript - 在 jQuery 中格式化数字的简单方法

javascript - 鼠标悬停在 IE7 中不起作用?

javascript - 将数字检索到数组中 - JavaScript

javascript - 为什么背景 css 属性在更新背景 div 的高度时分解为背景图像?

jquery:如何在不循环的情况下从元素中获取数据?

jquery - 在 JSON 数据中添加 HTML 元素

javascript - 温泉 UI - 列表调整大小