<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> New Document </title>
</head>
<body>
<!--<script>
var body = document.getElementById("body");
var childs = body.childNodes;
for (var i=0;i<childs.length;i++){
console.log(childs[i].nodeType);
console.log(childs[i].nodeName);
console.log(childs[i].nodeValue);
}
</script>-->
<div id="d1">
<input type="checkbox" name="class[]"/>语文
<input type="checkbox" name="class[]"/>数学
<input type="checkbox" name="class[]"/>英语
<input type="checkbox" name="class[]"/>政治
<br/>
<input type="checkbox" name="class[]"/>语文
<input type="checkbox" name="class[]"/>数学
<input type="checkbox" name="class[]"/>英语
<input type="checkbox" name="class[]"/>政治
<br/>
<input type="button" value="全选" id="all"/>
<input type="button" value="不选" id="none"/>
<input type="button" value="返选" id="prev"/>
</div>
<script>
var d1=document.getElementById("d1");
var childs=d1.childNodes;
var all=document.getElementById("all");
var none=document.getElementById("none");
var prev=document.getElementById("prev");
all.onclick=function(){
for(var i=0;i<childs.length;i++){
if(childs[i].nodeName=="INPUT"&&childs[i].type=="checkbox"){
childs[i].checked=true;
}
}
}
all.onclick=function(){
for(var i=0;i<childs.length;i++){
if(childs[i].nodeName == "INPUT"&&childs[i].type == "checkbox"){
childs[i].checked=false;
}
}
}
prev.onclick=function(){
for(var i=0; i<childs.length;i++){
id(childs[i].nodeName=="INPUT" && childs[i].type=="checkbox"){
if(childs[i].checked==true){childs[i].checked=false;
}else{
childs[i].checked=true;
}
}
}
}
</script>
</body>
</html>