js多兼容全选/反选代码
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js多兼容全选/反选代码</title>
<script language="javascript教程">
function Choose(sel, arg) //传递2个参数,分别是表名,选择参数(全/反选)
{
var objtb = document.getElementById(sel);
var num = objtb.getElementsByTagName("input");
for (i = 0; i < num.length; i++) {
if (num[i].tagName == "INPUT") {
if (arg == true) {
num[i].checked = true
}
else {
if (num[i].checked == true) {
num[i].checked = false;
}
else if (num[i].checked == false) {
num[i].checked = true;
}
}
}
}
}
</script>
</head>
<body>
<input name="" type="checkbox" value="">
<input name="" type="checkbox" value="">
<input name="" type="checkbox" value="">
<input name="" type="checkbox" value="">
<input name="" type="checkbox" value="">
<input name="" type="button" onClick="Choose(this, true)">
</div>
</body>
</html>