Checkbox 如何控制checkboxlist?
就是在权限分配的时候,一个CheckBox怎么控制
某一个Checkboxlist,因为我有多组分类,所以每一个checkbox都有要控
制的Checkboxlist.
请大家帮忙
------解决方案--------------------相同的分组, checkbox的name相同
如:
<form name= "form " ........>
AAA: <input name= "AAA " type=checkbox value= "1 "> AAA1 <br>
<input name= "AAA " type=checkbox value= "2 "> AAA2 <br>
<input name= "AAA " type=checkbox value= "3 "> AAA3 <br>
<input name= "AAA " type=checkbox value= "4 "> AAA4 <br>
BBB: <input name= "BBB " type=checkbox value= "1 "> BBB1 <br>
<input name= "BBB " type=checkbox value= "2 "> BBB2 <br>
<input name= "BBB " type=checkbox value= "3 "> BBB3 <br>
<input name= "BBB " type=checkbox value= "4 "> BBB4 <br>
</form>
然后可以用下面的方法遍历
<script>
function check(obj) {
if (typeof(obj)== "undefined ");
else if (typeof(obj.length)== "undefined ")
alert(obj.checked);
else
for (int i; i <obj.length; i++)
alert(obj[i].checked);
}
check(form.AAA);
check(form.BBB);
check(form.CCC);
</script>
细述不够清楚,不知道你想控制什么
------解决方案-------------------- <html>
<head>
<script>
function checkAll(obj, bol) {
if (typeof(obj)== "undefined ");
else if (typeof(obj.length)== "undefined ")
obj.checked = bol;
else
for (var i=0; i <obj.length; i++)
obj[i].checked = bol;
}
</script>
</head>
<body>
<form name= "form " action= " " method= "post ">
AA: <input name= "AA " type=checkbox value= "1 "> AA1 <br/>
<input name= "AA " type=checkbox value= "2 "> AA2 <br/>
<input name= "AA " type=checkbox value= "3 "> AA3 <br/>
<input name= "AA " type=checkbox value= "4 "> AA4 <br/>
<input type=checkbox value= " " onclick= "checkAll(form.AA, this.checked) "> 全选 <br/>
BB: <input name= "BB " type=checkbox value= "1 "> BB1 <br/>
<input name= "BB " type=checkbox value= "2 "> BB2 <br/>
<input name= "BB " type=checkbox value= "3 "> BB3 <br/>
<input name= "BB " type=checkbox value= "4 "> BB4 <br/>
<input type=checkbox value= " " onclick= "checkAll(form.BB, this.checked) "> 全选 <br/>
</form>
</body>
</html>