<div class="codetitle"> <span><a style="CURSOR: pointer" data="70887" class="copybut" id="copybut70887" onclick="doCopy('code70887')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code70887"><html> <br><head> <br><meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <br><title>同名元素的控制</title> <br><script language="javascript"> <br> function setFlag(aObj) <br> { <br> if (!aObj) <br> return false; <br> if(aObj.form.box.length>1) //超过一个 <br> { <br> for (i=0;i<aObj.form.box.length;i ) <BR> if (aObj.form.box[i]==aObj) <BR> if (aObj.form.box[i].checked) <BR> aObj.form.txt[i].value="ok"; <BR> else <BR> aObj.form.txt[i].value=""; <BR> } <BR> else <BR> { <BR> aObj.form.txt.value="oks"//如果只有一行(无重名) <BR> } <BR> } <BR></script> <br></head> <br><br><body> <br><form name="form1" method="post" action=""> <br>1<input name="box" type="checkbox" id="box" value="" onClick="javascript:setFlag(this);"/><input name="txt" type="text" id="txt" /><br> <br>2<input name="box" type="checkbox" id="box" value="" onClick="javascript:setFlag(this);" /><input name="txt" type="text" id="txt" /><br> <br>3<input name="box" type="checkbox" id="box" value="" onClick="javascript:setFlag(this);" /><input name="txt" type="text" id="txt" /> <br></form> <br></body> <br></html> </div> <br>