<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function change(obj)
{
var objs=document.getElementsByName(obj.name);
for(var i=0; i<objs.length; i++)
{
if(objs[i].id.substr(0,obj.id.length)==obj.id && objs[i].checked && objs[i]!=obj)return false;
}
for(var i=0; i<objs.length; i++)
{
if(obj.checked && obj.id.substr(0,objs[i].id.length)==objs[i].id)objs[i].checked=true;
}
for(var i=0; i<objs.length; i++)
{
if(obj.checked && objs[i].id.substr(0,obj.id.length)==obj.id)objs[i].checked=true;
}
return true;
}
//-->
</SCRIPT>
<form name="form1" method="post" action="b.jsp">
   <input type="checkbox" name="t"  id="101" value="101" onclick="return change(this);">上级<br>
      <input type="checkbox" name="t"  id="10101" value="10101" onclick="return change(this);">下一级一<br>
         <input type="checkbox" name="t"  id="10101001" value="10101001" onclick="return change(this);">下一级一再下一级<br>
      <input type="checkbox" name="t"  id="10102" value="10102" onclick="return change(this);">下一级二<br>
   <input type="checkbox" name="t"  id="10103" value="10102" onclick="return change(this);">下一级三<br>
   。。
<input name="submit" type="submit" value="提交" >
</form></BODY>

解决方案 »

  1.   

    如果你需要"父级选中后又取消,那么它的子级也全部取消",那么就不能实现"选择了子级中的任意一项,那么父级也必须checked,并且不能取消。"
    它们之间有些矛盾,如果你想实现"父级选中后又取消,那么它的子级也全部取消",去掉JS里的:
    for(var i=0; i<objs.length; i++)
    {
    if(objs[i].id.substr(0,obj.id.length)==obj.id && objs[i].checked && objs[i]!=obj)return false;
    }
    就可以了
      

  2.   

    哦~~不好意思,少改了一个地方,正解来了:
    <BODY>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function change(obj)
    {
    var objs=document.getElementsByName(obj.name);
    /*for(var i=0; i<objs.length; i++)
    {
    if(objs[i].id.substr(0,obj.id.length)==obj.id && objs[i].checked && objs[i]!=obj)return false;
    }*/
    for(var i=0; i<objs.length; i++)
    {
    if(obj.checked && obj.id.substr(0,objs[i].id.length)==objs[i].id)objs[i].checked=true;
    }
    for(var i=0; i<objs.length; i++)
    {
    if(objs[i].id.substr(0,obj.id.length)==obj.id)objs[i].checked=obj.checked;
    }
    return true;
    }
    //-->
    </SCRIPT>
    <form name="form1" method="post" action="b.jsp">
       <input type="checkbox" name="t"  id="101" value="101" onclick="return change(this);">上级<br>
          <input type="checkbox" name="t"  id="10101" value="10101" onclick="return change(this);">下一级一<br>
             <input type="checkbox" name="t"  id="10101001" value="10101001" onclick="return change(this);">下一级一再下一级<br>
          <input type="checkbox" name="t"  id="10102" value="10102" onclick="return change(this);">下一级二<br>
       <input type="checkbox" name="t"  id="10103" value="10102" onclick="return change(this);">下一级三<br>
       。。
    <input name="submit" type="submit" value="提交" >
    </form></BODY>