代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>全选反选</title>
</head>
<body>
<input type="checkbox" id="all">全选
<ul>
<li><input type="checkbox" class="all_check">看书</li>
<li><input type="checkbox" class="all_check">打篮球</li>
<li><input type="checkbox" class="all_check">唱</li>
<li><input type="checkbox" class="all_check">跳</li>
<li><input type="checkbox" class="all_check">rap</li>
</ul>
<script>
let all = document.querySelector('#all')
let all1 = document.querySelectorAll('ul>li>input')
all.onclick=function(){
if(all.checked == true){
for (i of all1){
i.checked = true
}
}else{
for(i of all1){
i.checked = false
}
}
}
</script>
</body>
</html>
结果
不嫌弃的点点关注,点点赞 ଘ(੭ˊᵕˋ)੭* ੈ✩‧