表單內(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) //超過(guò)一個(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://如果只有一行(無(wú)重名)
}
}
</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) //超過(guò)一個(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://如果只有一行(無(wú)重名)
}
}
</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)文章
javascript實(shí)現(xiàn)的左右選擇框效果代碼
javascript實(shí)現(xiàn)的左右選擇框效果代碼...2007-10-10
利用JavaScript更改input中radio和checkbox樣式
利用JavaScript更改input中radio和checkbox樣式的實(shí)現(xiàn)代碼。2009-11-11
用javascript將數(shù)據(jù)庫(kù)中的TEXT類型數(shù)據(jù)動(dòng)態(tài)賦值到TEXTAREA中
用javascript將數(shù)據(jù)庫(kù)中的TEXT類型數(shù)據(jù)動(dòng)態(tài)賦值到TEXTAREA中...2007-04-04
勾選時(shí)激活input 否則禁用的javascript代碼
唯一的可去之外是加了一點(diǎn)美化,使用戶體驗(yàn)更加一層樓,其中包括邊框的加粗,焦點(diǎn)的獲取,checkbox邊框線的隱藏等等。2009-12-12
javascript兼容firefox的文本輸入長(zhǎng)度提示
以下代碼是兼容firefox的文本輸入長(zhǎng)度提示,實(shí)時(shí)顯示輸入的字符長(zhǎng)度,當(dāng)超過(guò)輸入長(zhǎng)度的時(shí)候自動(dòng)截取。以實(shí)現(xiàn)文本輸入長(zhǎng)度限制,其中maxlength是設(shè)置的文本長(zhǎng)度上限。2008-06-06

