复选框的全选与反选
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div style="width: 100px; ">
<input class="big" type="checkbox">
<div>
<input class="ck" type="checkbox">
<input class="ck" type="checkbox">
<input class="ck" type="checkbox">
</div>
</div>
<script>
let bigcheck = document.querySelector('.big')
let check = document.querySelectorAll('.ck')
bigcheck.addEventListener('click', function(){
for(let i = 0; i < check.length; i++) {
check[i].checked = bigcheck.checked
}
})
for(let i = 0; i < check.length; i++){
check[i].addEventListener('click', function(){
for(let j = 0; j < check.length; j++){
if(check[j].checked == false){
bigcheck.checked = false
return
}
}
bigcheck.checked = true
})
}
</script>
</body>
</html>