全選與全不選
阿新 • • 發佈:2017-09-15
scrip chan checkbox true classname elements document false chang
<input type="checkbox" id="a" value="" />全選
<input type="checkbox" class="b" value="1" />1
<input type="checkbox" class="b" value="2" />2
<input type="checkbox" class="b" value="3" />3
<input type="checkbox" class="b" value="4" />4
<input type="checkbox" class="b" value="5" />5
<script>
var a = document.getElementById("a");
var b = document.getElementsByClassName("b");
var y = true
a.onchange = function(){
if(a.checked){
for(var i = 0 ; i<=b.length;i++)
b[i].checked = true;
}else{
for(var i = 0 ; i<=b.length;i++){
b[i].checked = false;
}
}
}
</script>
全選與全不選