私はこのコードをstackoverflowから取得しました。これは、非常に優れた「すべて選択」チェックボックスソリューションのように見えますが、2回目のクリック後に失敗する理由はありますか?
<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);
});
});