<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<input type="checkbox" name="" id="all" value="" />全选
<input type="checkbox" class="check_box" id="" value="" />1
<input type="checkbox" class="check_box" id="" value="" />2
<input type="checkbox" class="check_box" id="" value="" />3
<input type="checkbox" class="check_box" id="" value="" />4
<input type="checkbox" class="check_box" id="" value="" />5
<input type="checkbox" class="check_box" id="" value="" />6
<input type="checkbox" class="check_box" id="" value="" />7
<input type="checkbox" class="check_box" id="" value="" />8
<script>
var arrch=document.getElementsByClassName("check_box");
var oall=document.getElementById("all");
oall.onclick=function(){
if (oall.checked) {
for (i=0;i<arrch.length;i++) {
arrch[i].checked=true;
}
} else if(!oall.checked){
for (i=0;i<arrch.length;i++) {
arrch[i].checked=false;
}
}
}
for (j=0;j<arrch.length;j++) {
arrch[j].onclick=function(){
oall.checked=true;
for (x=0;x<arrch.length;x++) {
if(!arrch[x].checked){
oall.checked=false;
}
}
}
}
</script>
</body>
</html>
JS点击全选效果
最新推荐文章于 2022-08-12 09:18:32 发布