总结 先声明 两个框 在获取两个框 在用for循环辨别真假
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
.xuanze{width: 150px;height: 280px;border: 1px solid;border-radius: 5px;margin: 20px auto;padding: 5px 10px;}
.xuanze div{border-bottom: 1px solid #000;padding-bottom: 8px;margin-bottom: 8px;}
.xuanze input{margin:8px;}
</style>
<script type="text/javascript">
function quanxuanr(){
var quanxuan,gouxuan;
quanxuan=document.getElementById('quanxuan')
gouxuan=document.getElementsByName("gouxuan[]")
for (var i=0;i<gouxuan.length;i++) {
if (quanxuan.checked) {
gouxuan[i].checked=true;
}else{
gouxuan[i].checked=false;
}
}
}
</script>
</head>
<body>
<div>
<div>
<input type="checkbox" id="quanxuan" onclick="quanxuanr()"><label for="quanxuan">全选</label>
</div>
<input type="checkbox" name="gouxuan[]">1<br>
<input type="checkbox" name="gouxuan[]">2<br>
<input type="checkbox" name="gouxuan[]">3<br>
<input type="checkbox" name="gouxuan[]">4<br>
<input type="checkbox" name="gouxuan[]">5<br>
<input type="checkbox" name="gouxuan[]">6<br>
<input type="checkbox" name="gouxuan[]">7<br>
<input type="checkbox" name="gouxuan[]">8<br>
</div>
</body>
</html>