<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<table border="1px" id="tb">
<tr>
<td>
<input type="checkbox" onClick="fun()" id="tb1">
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="cb1" >
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="cb1">
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="cb1">
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="cb1">
</td>
</tr>
</table>
<script>
function fun(){
var a = document.getElementById("tb1")
var b = a.checked;
//获取的状态(是否选择)
var c = document.getElementsByName("cb1");
if(b==true){
for(var i=0;i<c.length;i++){
var d = c[i];
d.checked = true;
}
}else {
for(var i=0;i<c.length;i++){
var d = c[i];
d.checked = false;
}
}
}
</script>
</body>
</html>
9.2全选和全不选
最新推荐文章于 2021-11-03 21:03:41 发布