实现界面
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>练习</title>
<script>
//全选和全不选
function allCheck(name,boolValue) {
var allvalue = document.getElementsByName(name);
//遍历判断
for (var i = 0; i < allvalue.length; i++) {
if (allvalue[i].type == "checkbox")
allvalue[i].checked = boolValue;
}
}
//反选
function reserveCheck(name){
var revalue = document.getElementsByName(name);
//遍历判断
for(i=0;i<revalue.length;i++){
if(revalue[i].checked == true)
revalue[i].checked = false;
else
revalue[i].checked = true;
}
}
</script>
</head>
<body>
<div >
<label><input type="checkbox" name="choice" id="choice" width="30px;"/></label>全选
<p></p>
<label><input type="checkbox" name="choice" id="choice" width="30px;"/></label>吃
<label><input type="checkbox" name="choice" id="choice" width="30px;"/></label>睡
<label><input type="checkbox" name="choice" id="choice" width="30px;"/></label>学习
<p></p>
//给button添加JS
<button onclick="javascript:allCheck('choice',true)">全选</button>
<button onclick="javascript:allCheck('choice',false)">全不选</button>
<button onclick="javascript:reserveCheck('choice')">反选</button>
</div>
</body>
</html>