<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="button" id="but1" value="全选" />
<input type="button" id="but2" value="取消全选" />
<input type="button" id="but3" value="反选" /><br />
<input type="checkbox" name="but" value="" /><br />
<input type="checkbox" name="but" value="" /><br />
<input type="checkbox" name="but" value="" /><br />
<input type="checkbox" name="but" value="" /><br />
<input type="checkbox" name="but" value="" /><br />
<input type="checkbox" name="but" value="" /><br />
<input type="checkbox" name="but" value="" /><br />
<input type="checkbox" name="but" value="" /><br />
共有<font id="p1"> </font>件
</body>
<script type="text/javascript">
var s=0;
var s1=0;
var s2=0;
var but1=document.getElementById("but1");
but1.onclick=function(){
var but=document.getElementsByName("but");
console.log(but);
for(i=0;i<but.length;i++){
but[i].checked=true;
s++;
console.log(s);
}
var p1=document.getElementById("p1");
p1.innerHTML=s;
}
var but2=document.getElementById("but2");
but2.onclick=function(){
var but=document.getElementsByName("but");
for(i=0;i<but.length;i++){
but[i].checked=false;
}
document.getElementById("p1").innerHTML=0;
}
var but3=document.getElementById("but3");
var but=document.getElementsByName("but");
but3.onclick=function(){
for(i=0;i<but.length;i++){
if(but[i].checked==true){
but[i].checked=false;
}else{
but[i].checked=true;
}
}
}
</script>
</html>