平时常用一个小功能
var check_all = document.getElementsByName('student_box');
var check_flag = true;
function checkAll(_this){
check_flag = !check_flag;
_this.checked = check_flag; if(_this.checked){
for(var i = 0;i<check_all.length;i++){
check_all[i].checked=false;
}
}else{
for(var i = 0;i<check_all.length;i++){
check_all[i].checked=true;
}
} }
<input type="checkbox" name="student_box" id="check_all" onclick="checkAll(this)" /> <input type="checkbox" name="student_box" />