<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div>
<label><input type="checkbox" name="aAll">全选</label><br>
<label><input type="checkbox" name="a">A</label><br>
<label><input type="checkbox" name="a">B</label><br>
<label><input type="checkbox" name="a">C</label>
</div>
<script type="text/javascript">
var all = document.getElementsByName("aAll")[0];
var aCheck = document.getElementsByName("a");
all.onclick = function(){
if(this.checked){
for(var i of aCheck){
i.checked = true;
}
}else{
for(var i of aCheck){
i.checked = false;
}
}
}
for(var i of aCheck){
i.onclick = function(){
if(!this.checked){
all.checked = false;
}
}
}
</script>
</body>
</html>