全选,反选
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function fun(){
var allNode=document.getElementsByName("all");
var allNode=allNode[0];
var produceNodes=document.getElementsByName("produce");
for( i=0;i<produceNodes.length;i++){
produceNodes[i].checked=allNode.checked;
}
}
function fun1(){
var fanNode=document.getElementsByName("fan");
var fanNode=fanNode[0];
var produceNodes=document.getElementsByName("produce");
for( i=0;i<produceNodes.length;i++){
if(produceNodes[i].checked)
produceNodes[i].checked=false;
else
produceNodes[i].checked=true;
}
}
</script>
</head>
<body>
<input type="checkbox" name="all" onclick="fun()">全选<br>
<input type="checkbox" name="produce">华为电脑<br>
<input type="checkbox" name="produce">联想电脑<br>
<input type="checkbox" name="produce">小米电脑<br>
<input type="checkbox" name="fan" onclick="fun1()">反选<br>
</body>
</html>