<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style type="text/css">
</style>
</head>
<body>
<table border="1">
<tr>
<th><input type="checkbox" class="choose-all-input" onclick="clickChooseAllInput()" /></th>
<th>学号</th>
<th>姓名</th>
<th>班级</th>
</tr>
<tr>
<td><input type="checkbox" class="choose-single" /></td>
<td>001</td>
<td>张三</td>
<td>李四</td>
</tr>
<tr>
<td><input type="checkbox" class="choose-single" /></td>
<td>002</td>
<td>张三</td>
<td>李四</td>
</tr>
<tr>
<td><input type="checkbox" class="choose-single" /></td>
<td>003</td>
<td>张三</td>
<td>李四</td>
</tr>
<tr>
<td><input type="checkbox" class="choose-single" /></td>
<td>004</td>
<td>张三</td>
<td>李四</td>
</tr> <tr>
<td><input type="checkbox" class="choose-single" /></td>
<td>005</td>
<td>张三</td>
<td>李四</td>
</tr>
<tr>
<td><input type="checkbox" class="choose-single" /></td>
<td>002</td>
<td>F20</td>
<td>F20</td>
</tr>
</table>
<button onclick="clickChooseAllBtn()">全选</button>
<button onclick="clickChooseReverse()">反选</button>
</body>
<script type="text/javascript">
var chooseAllInputEle = document.getElementsByClassName("choose-all-input")[0];
var chooseSingleEles = document.getElementsByClassName("choose-single");
function clickChooseAllInput() {
if (chooseAllInputEle.checked) {
choose("selected");
} else {
choose("");
}
}
function clickChooseAllBtn() {
chooseAllInputEle.checked = "checked";
choose("selected");
}
function choose(status) {
for (var i = 0; i < chooseSingleEles.length; i++) {
chooseSingleEles[i].checked = status;
}
}
function clickChooseReverse() {
for (var i = 0; i < chooseSingleEles.length; i++) {
if (chooseSingleEles[i].checked) {
chooseSingleEles[i].checked = "";
} else {
chooseSingleEles[i].checked = "checked";
}
}
}
</script>
</html>
相关文章
- 07-21Checkbox复选框实现全选和全不选功能
- 07-21原生js实现在表格用鼠标框选并有反选功能
- 07-21js实现checkbox全选以及反选
- 07-21jQuery实现的全选、反选和不选功能
- 07-21jQuery实现的全选、反选和不选功能
- 07-21js-类似邮箱中的删除文件-全选、不选、反选
- 07-21JS实现全选反选
- 07-21原生JS实现全选和不全选
- 07-21Hmtl页面中Jquery实现复选框选择-全选-全不选-反选-提交
- 07-21js实现多选、全选、反选、取消选择(篇一)