<body>
<table>
<tr>
<td>
<input type="checkbox" id="check_all" />
<label for="check_all">全选</label>
<input type="checkbox" id="reverse" />
<label for="reverse">反选</label>
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="items" />
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="items" />
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="items" />
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="items" />
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="items" />
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="items" />
</td>
</tr>
</table>
</body>
</html>
<script>
var check = document.getElementById("check_all");
var reverse = document.getElementById("reverse");
var items = document.getElementsByClassName("items");
check.onchange = function() {
if(check.checked) {
for(var x in items) {
items[x].checked = true;
}
} else {
for(var x in items) {
items[x].checked = false;
}
}
}
for(var z in items) {
items[z].onchange = function() {
if(!this.checked) {
check.checked = false;
}else{
var status = 0;
for(var y in items){
if(items[y].checked == false){
status = 1;
alert(y);
}
}
if(status == 0){
check.checked = true;
}
}
}
}
reverse.onclick = function(){
for(var x in items){
items[x].checked = items[x].checked?false:true;
}
}
</script>
全选框
1.点全选 全部选择
2.取消全选 全部取消选择
3.全选时 取消单个选项 全选框取消选择
4.未全选时 所有单个选项选择 全选框选择
5.反选按钮
浙公网安备 33010602011771号