【发布时间】:2012-07-26 21:19:41
【问题描述】:
我正在使用 jQuery 的事件委托向表格行添加点击事件。我在该行的第一个 td 中也有一个复选框。当我单击行中的任意位置时,一切都按预期工作。但是,当我单击复选框时,我不希望该事件起作用。我尝试使用 :not() 选择器,但也许我遗漏了一些东西,因为当我单击复选框时我仍在触发事件。
HTML
<tr>
<td>
<div class="myCheckbox"><input type="checkbox" name="userName" /></div>
</td>
<td><a href="/go/to/user/profile"></a></td>
<td>more info</td>
<td>more info</td>
<td>more info</td>
</tr>
jQuery
$('table tr:not(':checkbox')').on('click', 'td', function(event) {
// Do something
});
我可以得到帮助来解决我正在尝试做的事情吗?
【问题讨论】:
标签: javascript jquery event-delegation