递归选中某页面的checkbox函数
脚本如下:为什么只能递归到第一个分支?
比如:
1选项一
2 选项一一
3 选项一一一
4 选项一一二
5 选项一一三
6 选项一二
7 选项一二一
8 选项一二二
9 选项一三为什么下面的脚本只能将1到5的选项选上??函数说明:
obj为某父节点。
act指checkbox的name中需包含的字符串
parent和haschild为checkbox中自定义的属性
function selectchild(obj,act)
{
var all=document.getElementsByTagName("input");
for(i=0; i<all.length; i++)
{
if(all[i].type=="checkbox")
{
if(all[i].name.indexOf(act)!=-1)
{
if(all[i].parent==obj.value)
{
if(!all[i].disabled)
{
if(obj.checked)
{
all[i].checked=true;
}
else
{
all[i].checked=false;
}
if(all[i].haschild=="true")
{
target=obj.id;
alert(target);
selectchild(all[i],act);
obj=document.getElementById(target);
alert(target);
}
}
}
}
}
}
}猜测可能是引用传递的问题,可是不知道怎么解决。
脚本如下:为什么只能递归到第一个分支?
比如:
1选项一
2 选项一一
3 选项一一一
4 选项一一二
5 选项一一三
6 选项一二
7 选项一二一
8 选项一二二
9 选项一三为什么下面的脚本只能将1到5的选项选上??函数说明:
obj为某父节点。
act指checkbox的name中需包含的字符串
parent和haschild为checkbox中自定义的属性
function selectchild(obj,act)
{
var all=document.getElementsByTagName("input");
for(i=0; i<all.length; i++)
{
if(all[i].type=="checkbox")
{
if(all[i].name.indexOf(act)!=-1)
{
if(all[i].parent==obj.value)
{
if(!all[i].disabled)
{
if(obj.checked)
{
all[i].checked=true;
}
else
{
all[i].checked=false;
}
if(all[i].haschild=="true")
{
target=obj.id;
alert(target);
selectchild(all[i],act);
obj=document.getElementById(target);
alert(target);
}
}
}
}
}
}
}猜测可能是引用传递的问题,可是不知道怎么解决。
解决方案 »
- 编程疑惑
- 请教各位,用asp.net做的系统用什么保存用户信息好呢?
- 菜菜请教:如何让DataGrid只显示一条记录?
- 关于TreeView数型控件动态绑定
- HttpApplication和HttpApplicationState是什么关系?
- 日期拆分
- AjaxPro使用Session中,第一次可以,提交后就不行了?怎么回事
- 打不开.csproj工程文件
- 推荐一本asp.net入门好书,谢谢!
- datagrid 帮定金额列的显示格式的问题
- 数据库插入超时,比较紧急向大家求教了
- |M| 做了一个页面接口cs文件在里面添加一个Onload事件,但这个事件比Page.Load后执行,我要他先执行怎么办
注意包含
<HEAD>
<script>
var target;
function selectchild(obj,act)
{
var all=document.getElementsByTagName("input");
for(i=0; i<all.length; i++)
{
if(all[i].type=="checkbox")
{
if(all[i].name.indexOf(act)!=-1)
{
if(all[i].parent==obj.value)
{
if(!all[i].disabled)
{
if(obj.checked)
{
all[i].checked=true;
}
else
{
all[i].checked=false;
}
if(all[i].haschild=="true")
{
target=obj.id;
alert(target);
selectchild(all[i],act);
obj=document.getElementById(target);
alert(target);
}
else
{
continue;
}
}
}
}
}
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<div id="AccessGroup" style="OVERFLOW: scroll; WIDTH: 400px; POSITION: relative; HEIGHT: 200px">
<input type="checkbox" parent="-1" id="access" name="access" value="0" onclick="selectchild(this,'access')">全部系统用户组
<br>
<input type="checkbox" id="access_1" parent="0" haschild="true" name="access_1" value="1" onclick="selectchild(this,'access')">超级管理员组
<br>
<input type="checkbox" id="access_2" parent="1" haschild="false" name="access_2" value="5">管理员一组
<br>
<input type="checkbox" id="access_3" parent="1" haschild="false" name="access_3" value="6">管理员二组
<br>
<input type="checkbox" id="access_4" parent="1" haschild="false" name="access_4" value="7">管理员三组
<br>
<input type="checkbox" id="access_5" parent="0" haschild="true" name="access_5" value="2" onclick="selectchild(this,'access')">普通用户组
<br>
<input type="checkbox" id="access_6" parent="2" haschild="false" name="access_6" value="8">普通用户一组
<br>
<input type="checkbox" id="access_7" parent="2" haschild="false" name="access_7" value="9">普通用户二组
<br> <input type="checkbox" id="access_8" parent="0" haschild="false" name="access_8" value="3">匿名用户组
<br> <input type="checkbox" id="access_9" parent="0" haschild="false" name="access_9" value="4">待审用户组
</div>
</body>
</html>