<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
window.onload= function () {
var btn=document.getElementById('btn');
var btn2=document.getElementById('btn2');
var btn3=document.getElementById('btn3');
var con=document.getElementById('con');
var checks=con.getElementsByTagName('input');
btn.onclick= function () {
for(var i=0;i<checks.length;i++){
checks[i].checked=true;
}
};
btn2.onclick= function () {
for(var i=0;i<checks.length;i++){
checks[i].checked=false;
}
};
btn3.onclick= function () {
for(var i=0;i<checks.length;i++){
if(checks[i].checked){
checks[i].checked=false;
}else{
checks[i].checked=true;
}
}
}
};
</script>
</head>
<body>
<input type="button" value="全选" id="btn"/><br />
<input type="button" value="全不选" id="btn2"/><br />
<input type="button" value="反选" id="btn3"/><br />
<div id="con">
<input type="checkbox"/><br />
<input type="checkbox"/><br />
<input type="checkbox"/><br />
<input type="checkbox"/><br />
<input type="checkbox"/><br />
<input type="checkbox"/><br />
<input type="checkbox"/><br />
<input type="checkbox"/><br />
<input type="checkbox"/><br />
<input type="checkbox"/><br />
<input type="checkbox"/><br />
<input type="checkbox"/><br />
</div>
</body>
</html>