<html>
<head>
<title>全选和取消全选</title>
</head>
<body>
<script type="text/javascript">
window.onload=function(){
var all=document.getElementById("all")
var ckb=document.getElementsByName("ckb")
all.onclick=function(){
for(var i=0;i<ckb.length;i++){
ckb[i].checked=all.checked
}
}
var checkdNumber=0//记录单击复选框的按钮次数
for(var i=0;i<ckb.length;i++){
ckb[i].onclick=function(){
checkdNumber++
if(checkdNumber==ckb.length){
all.checked=true
}
else{
all.checked=false
}
}
}
}
</script>
<input type="checkbox" id="all">全选/全不选<br>
<input type="checkbox" name="ckb">篮球<br>
<input type="checkbox" name="ckb">足球<br>
<input type="checkbox" name="ckb">排球<br>
<input type="checkbox" name="ckb">网球<br>
</body>
</html>