我有一个结构如下的表:
<table>
<tr id="ui-id-7" onclick="editThis();">
<td>100</td>
<td>Test</td>
<td class="noEdit"><a href="www.mysite.com" target="_blank"><img src="www.mysite.com/test.jpg"></a></td>
</tr>
</table>
我需要的是:整个<tr>
可点击并调用 editThis()
方法,除非用户单击 <td>
具有 link 元素(如果是 noEdit
类的元素)。
在上面的代码中,单击 ANY <td>
(或 <tr>
)将调用 editThis()
方法。我知道我可以为每个 <td>
编写调用而不是 <tr>
,但这会写很多东西......
这可能吗?
最佳答案
$('#ui-id-7 td.noEdit').click(function(e){
e.stopPropagation();
});
Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event
关于jquery - 单击 <tr>,但前提是单击的 <td> 不是 <a>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21915341/