需求:使用 jquery 实现 checkbox 的全选与全不选。效果如图:
<table class="bigtable">
<tr class="first_tr">
<td class="check"><input type="checkbox" id="check_all" />全选</td>
</tr>
<tr>
<td class="check"><input type="checkbox" name="chk_list" id="check"/></td>
</tr>
<tr>
<td class="check"><input type="checkbox" name="chk_list" id="check" /></td>
</tr>
<tr>
<td class="check"><input type="checkbox" name="chk_list" id="check"/></td>
</tr>
<tr>
<td class="check"><input type="checkbox" name="chk_list" id="check" /></td>
</tr>
<tr>
<td class="check"><input type="checkbox" name="chk_list" id="check" /></td>
</tr>
</table>
关键的 jquery 代码:
$(function(){
$("#check_all").click(function(){
$("input[ name='chk_list']").attr("checked",$(this).prop("checked"));
});
});