<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<input type="checkbox" id="div1" name="ite"><span>杨幂</span><br>
<input type="checkbox" id="div2" name="ite"><span>范冰冰</span> <br>
<input type="checkbox" id="div3" name="ite"><span>张天爱</span> <br>
<input type="checkbox" id="div4" name="ite"><span>迪丽热巴</span> <br>
<input type="checkbox" id="div4" name="ite"><span>古力娜扎</span> <br>
<input type="button" value="全选" id="quanxuan">
<input type="button" value="全不选" id="quanbuxuan">
<input type="button" value="反选" id="fanxuan">
<script type="text/javascript">
//全选
document.getElementById('quanxuan').onclick=function(){
// 获取所有的复选框
var name=document.getElementsByName('ite');
for(var i=0;i<name.length;i++){
var che=name[i];
che.checked="checked",true;
}
}
//全不选
document.getElementById('quanbuxuan').onclick=function(){
// 获取所有的复选框
var name=document.getElementsByName('ite');
for(var i=0;i<name.length;i++){
var che=name[i];
che.checked="checked",false;
}
}
//反选
document.getElementById('fanxuan').onclick=function(){
// 获取所有的复选框
var inputs=document.getElementsByName('ite');
for(var i=0;i<inputs.length;i++){
var checkElement=inputs[i];
inputs[i].checked = !inputs[i].checked;
}
}
</script>
</body>
</html>