js小效果-全选

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script>
window.onload=function(){
var aBtn=document.getElementsByTagName('input');
var count=0;
aBtn[0].onclick=function(){
if(this.checked==true){
for(var i=1;i<aBtn.length;i++){
aBtn[i].checked=true;
}
count=aBtn.length-1;
document.title=count;
}else{
for(var i=1;i<aBtn.length;i++){
aBtn[i].checked=false;
}
count=0;
document.title=count;
}

};
for( var i=1;i<aBtn.length;i++){
aBtn[i].onclick=function(){
if(this.checked==true){
count++;
}else{
count--;
}
if(count==aBtn.length-1){
aBtn[0].checked=true;
}else{
aBtn[0].checked=false;
}
document.title=count;
}
};
}
</script>
</head>
<body>
<input type="checkbox" />
<hr/>
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
</body>
</html>
原文地址:https://www.cnblogs.com/HUANGRONG888/p/6081584.html