<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>
<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>
解决方案 »
- 求助正则表达式的写法
- 【求助】JavaScript如何让PNG图片在IE6下面透明
- javascript 初学 关于onmouseover onmouseout的输出
- stack overflow at line 340网页报错
- 二维数组 for 循环 取值 ???
- Javascript 返回Nan
- 虽然没有分数,但是还要问问js高手!
- 求助 js 代码
- 我想在页面用点击一个按钮,弹出一个窗口,在窗口显示一个下载的按钮,在这个窗口里实现下载功能,我改怎么办,高手帮我,加分
- 把字符型转成日期型(按照两种格式.YYYY-MM-DD与YYYYMMDD)
- 如何提示用户保存文件?
- 请教有关用层模拟下拉菜单的一些问题!
它们之间有些矛盾,如果你想实现"父级选中后又取消,那么它的子级也全部取消",去掉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;
}
就可以了
<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>