JS实现复选框全选全不选以及子复选框带动全选框的选中

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript">
function selectAll(o)
{
var a = document.getElementsByName("m");
for (var i=0;i<a.length;i++){
a[i].checked = o.checked;
}

}

function checkOne(obj){
if(!obj.checked){
document.getElementById("all").checked = obj.checked;
}
var b = true;
var arr = document.getElementsByName(obj.name);
for(var i=0;i<arr.length;i++){
if(!arr[i].checked){b=false; break;}
}
document.getElementById("all").checked = b;
}

</script>
</head>
<body>
<table>
<tr>
<td>全选<input type="checkbox" id="all" onclick="selectAll(this)"/></td>
</tr>
<tr>
<td><input type="checkbox" name="m" onclick="checkOne(this)"/></td>
</tr>
<tr>
<td><input type="checkbox" name="m" onclick="checkOne(this)"/></td>
</tr>
<tr>
<td><input type="checkbox" name="m" onclick="checkOne(this)"/></td>
</tr>
<tr>
<td><input type="checkbox" name="m" onclick="checkOne(this)"/></td>
</tr>
<tr>
<td><input type="checkbox" name="m"/></td>
</tr>
</table>

<a href="javascript:selectOne()">asdadasdd</a>
</body>
</html>

上一篇: (五) 广播机制


下一篇:VS发布,TFS邮件设置截图