我正在使用jQuery的事件委託向錶行添加單擊事件。我在該行的第一個td中也有一個複選框。當我點擊行中的任何地方時,一切都按預期工作。不過,當我點擊複選框時,我不希望事件發揮作用。我試過使用:not()選擇器,但也許我錯過了一些東西,因爲當我單擊複選框時,仍然觸發事件。如何忽略td內的複選框
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
});
我可以幫助解決我正在嘗試做的事嗎?
[父事件處理程序的執行防止]的可能重複(http://stackoverflow.com/questions/1398582/prevent-execution-of-parent-event-handler) – 2012-07-26 21:22:22