$('input[name="selectall"]').click(function(){
//input[name="selectall"]:实现全选与全部选的checkbox
//alert(this.checked);
if($(this).is(':checked')){
$('input[name="stuCheckBox"]').each(function(){
//input[name="stuCheckBox"]:被选中的CheckBox
//此处如果用attr,会出现第三次失效的情况
$(this).prop("checked",true);
});
}else{
$('input[name="stuCheckBox"]').each(function(){
$(this).removeAttr("checked",false);
});
//$(this).removeAttr("checked");
}
});
<td><input type="checkbox" name="selectall"/></td>
<td><input type="checkbox" name="stuCheckBox" /></td>