html<html<head lang="en"<meta charset="UTF-8"<titletitle</head<body<div id="div1"<input type="checkbox"<input type="checkbox"<input type="checkbox"<input type="checkbox"<input type="checkbox"</div<div<input type="button" onclick="selall()" value="全选"<input type="button" onclick="selnone()" value="全不选"<input type="button" onclick="selreverse()" value="反选"</div<scriptfunction selall(){
var div1 = document.getElementById('div1');
var ins = div1.getElementsByTagName('input');
for(var i=0; i<ins.length; i++){
if(ins[i].type=='checkbox'){
ins[i].checked = true;
}
}
}
function selnone(){
var div1 = document.getElementById('div1');
var ins = div1.getElementsByTagName('input');
for(var i=0; i<ins.length; i++){
if(ins[i].type=='checkbox'){
ins[i].checked = false;
}
}
}
function selreverse(){
var div1 = document.getElementById('div1');
var ins = div1.getElementsByTagName('input');
for(var i=0; i<ins.length; i++){
if(ins[i].type=='checkbox'){
ins[i].checked = !ins[i].checked;
}
}
}
script</body</html>