87,907
社区成员
发帖
与我相关
我的任务
分享
function ChildrenCheck(pid)
{
ParentID=document.getElementById("Forum_"+pid); //此处获取当前点击的父CHECKBOX的ID
ChildrenName=document.getElementsByName("Forum"+pid); //此处表示所有NAME=父级复选框ID的checkbox
//alert(ChildrenName.length);
if (ChildrenName.length>0){
for (i=0;i<ChildrenName.length;i++)
{
newpid=ChildrenName[i].id.split("_")[1];
NowChildrenName=ChildrenName[i];
if (ParentID.checked==true)
{
NowChildrenName.checked=true;
NowChildrenName.disabled=true;
}
else
{
NowChildrenName.checked=false;
NowChildrenName.disabled=false;
}
ChildrenCheck(newpid); //初步怀疑问题出现这里,这边调用的时候又一次出现了i这个变量,导致循环走不下去
}
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script type="text/javascript">
function ChildrenCheck(pid)
{
var ParentID=document.getElementById("Forum_"+pid); //此处获取当前点击的父CHECKBOX的ID
var ChildrenName=document.getElementsByName("Forum"+pid); //此处表示所有NAME=父级复选框ID的checkbox
//alert(ChildrenName.length);
if (ChildrenName.length>0){
for (var i=0;i<ChildrenName.length;i++)
{
newpid=ChildrenName[i].id.split("_")[1];
NowChildrenName=ChildrenName[i];
if (ParentID.checked==true)
{
NowChildrenName.checked=true;
NowChildrenName.disabled=true;
}
else
{
NowChildrenName.checked=false;
NowChildrenName.disabled=false;
}
ChildrenCheck(newpid); //初步怀疑问题出现这里,这边调用的时候又一次出现了i这个变量,导致循环走不下去[/color]
}
}
}
</script>
<style type="text/css">
#div {
width:450px;
height:450px;
}
#div a{
position:absolute;
}
</style>
</head>
<body><table> <tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;">┗</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_14" name="Forum0" onClick="ChildrenCheck('14');" value="14" />大板块2
</font></td>
</tr>
<tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;"> ┣</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_15" name="Forum14" onClick="ChildrenCheck('15');" value="15" />小板块2-1
</font></td>
</tr>
<tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;"> ┃┣</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_18" name="Forum15" onClick="ChildrenCheck('18');" value="18" />小板块2-1-2
</font></td>
</tr>
<tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;"> ┃┗</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_16" name="Forum15" onClick="ChildrenCheck('16');" value="16" />小板块2-1-1
</font></td>
</tr>
<tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;"> ┗</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_17" name="Forum14" onClick="ChildrenCheck('17');" value="17" />小板块2-2
</font></td>
</tr>
<tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;"> ┣</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_19" name="Forum17" onClick="ChildrenCheck('19');" value="19" />小板块2-2-1
</font></td>
</tr>
<tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;"> ┣</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_20" name="Forum17" onClick="ChildrenCheck('20');" value="20" />小板块2-2-2
</font></td>
</tr>
<tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;"> ┗</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_21" name="Forum17" onClick="ChildrenCheck('21');" value="21" />小板块2-2-3
</font></td>
</tr>
</table></body>
</html>
<tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;">┗</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_14" name="Forum0" onClick="ChildrenCheck('14');" value="14" />大板块2
</font></td>
</tr>
<tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;"> ┣</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_15" name="Forum14" onClick="ChildrenCheck('15');" value="15" />小板块2-1
</font></td>
</tr>
<tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;"> ┃┣</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_18" name="Forum15" onClick="ChildrenCheck('18');" value="18" />小板块2-1-2
</font></td>
</tr>
<tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;"> ┃┗</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_16" name="Forum15" onClick="ChildrenCheck('16');" value="16" />小板块2-1-1
</font></td>
</tr>
<tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;"> ┗</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_17" name="Forum14" onClick="ChildrenCheck('17');" value="17" />小板块2-2
</font></td>
</tr>
<tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;"> ┣</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_19" name="Forum17" onClick="ChildrenCheck('19');" value="19" />小板块2-2-1
</font></td>
</tr>
<tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;"> ┣</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_20" name="Forum17" onClick="ChildrenCheck('20');" value="20" />小板块2-2-2
</font></td>
</tr>
<tr onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor=''">
<td align="Left" valign="middle"><font color="#FF9900" style="font-size:22px; line-height:19px;"> ┗</font> <font style="font-weight:bold;font-size:14px;">
<input type="checkbox" id="Forum_21" name="Forum17" onClick="ChildrenCheck('21');" value="21" />小板块2-2-3
</font></td>
</tr>