【发布时间】:2013-02-07 09:14:40
【问题描述】:
我从 stackoverflow 得到这段代码,它看起来像是一个很好的“全选”复选框解决方案,有什么想法为什么它在第二次点击后失败?
<table>
<tr>
<td>
<input type='checkbox' value='0' class=''>
</td>
<td>
<input type='checkbox' value='0' class=''>
</td>
<td>
<input type='checkbox' value='0' class=''>
</td>
<td width="100" align="right">
select all <input type='checkbox' value='0' class='selectall2'>
</td>
</tr>
</table>
$(document).ready(function () {
$(document).on("click", ".selectall2", function () {
$(this).closest('tr').find('input[type=checkbox]').attr('checked', this.checked);
});
});
【问题讨论】: