我想删除onclick具体的所有s tr..
例如,
之前:
<tr id="current">
<td onclick="foo();"></td>
<td onclick="foo();"><div onclick="abc();"></div></td>
<td onclick="foo();"></td>
<td onclick="foo();"></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
后:
<tr id="current">
<td></td>
<td><div></div></td>
<td></td>
<td></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我想我必须做的事情如下:
$("#current td").each(function() {
$(this).removeAttr('onclick');
});
$("#current td div").each(function() {
$(this).removeAttr('onclick');
});
Run Code Online (Sandbox Code Playgroud)
但也许还有另一种选择.
使用.off()
$("#current").find("*").off();
Run Code Online (Sandbox Code Playgroud)
find("*")将找到包含的所有元素#current.这足以删除所有onclick事件(两者<td>和<div>).