表單內(nèi)同名元素的控制
更新時(shí)間:2006年11月22日 00:00:00 作者:
復(fù)制代碼 代碼如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>同名元素的控制</title>
<script language="javascript">
function setFlag(aObj)
{
if (!aObj)
return false;
if(aObj.form.box.length>1) //超過一個(gè)
{
for (i=0;i<aObj.form.box.length;i++)
if (aObj.form.box[i]==aObj)
if (aObj.form.box[i].checked)
aObj.form.txt[i].value="ok";
else
aObj.form.txt[i].value="";
}
else
{
aObj.form.txt.value="oks"http://如果只有一行(無重名)
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
1<input name="box" type="checkbox" id="box" value="" onClick="javascript:setFlag(this);"/><input name="txt" type="text" id="txt" /><br>
2<input name="box" type="checkbox" id="box" value="" onClick="javascript:setFlag(this);" /><input name="txt" type="text" id="txt" /><br>
3<input name="box" type="checkbox" id="box" value="" onClick="javascript:setFlag(this);" /><input name="txt" type="text" id="txt" />
</form>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>同名元素的控制</title>
<script language="javascript">
function setFlag(aObj)
{
if (!aObj)
return false;
if(aObj.form.box.length>1) //超過一個(gè)
{
for (i=0;i<aObj.form.box.length;i++)
if (aObj.form.box[i]==aObj)
if (aObj.form.box[i].checked)
aObj.form.txt[i].value="ok";
else
aObj.form.txt[i].value="";
}
else
{
aObj.form.txt.value="oks"http://如果只有一行(無重名)
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
1<input name="box" type="checkbox" id="box" value="" onClick="javascript:setFlag(this);"/><input name="txt" type="text" id="txt" /><br>
2<input name="box" type="checkbox" id="box" value="" onClick="javascript:setFlag(this);" /><input name="txt" type="text" id="txt" /><br>
3<input name="box" type="checkbox" id="box" value="" onClick="javascript:setFlag(this);" /><input name="txt" type="text" id="txt" />
</form>
</body>
</html>
相關(guān)文章
比較實(shí)用的復(fù)選框的實(shí)用javascript腳本
比較實(shí)用的復(fù)選框的實(shí)用javascript腳本...2007-09-09仿校內(nèi)登陸框,精美,給那些很厲害但是沒有設(shè)計(jì)天才的程序員
寫代碼對于我們來說很簡單,但是做個(gè)布局設(shè)計(jì)簡直是登天啊2008-11-11判斷多個(gè)元素(RADIO,CHECKBOX等)是否被選擇的原理說明
多個(gè)元素(RADIO,CHECKBOX等)是否被選擇,常用的就是下面的方法,大家可以研究下。2009-02-02表單項(xiàng)的name命名為submit、reset引起的問題
最近朋友使用了form的一個(gè)表單命名為關(guān)鍵詞引起了無法reset和提交.原來是這個(gè)問題2007-12-12