js Form.elements[i]的使用實(shí)例
更新時(shí)間:2011年11月13日 23:36:43 作者:
js Form.elements[i]的使用實(shí)例,這樣的代碼比document.form1的使用兼容性更好。
復(fù)制代碼 代碼如下:
//檢查表單元素是否為空
function check(Form)
{
for (i=0;i<Form.length;i++){
if(Form.elements[i].value == "")
{
//Form的屬性elements的首字e要小寫
alert(Form.elements[i].name + "不能為空!");
Form.elements[i].focus();
//指定表單元素獲得焦點(diǎn)
return;
}
}
Form.submit();
}
調(diào)用
<form name="form1" method="post" action="">
留 言 人:<input type="text" name="mname" size="20">
留言主題:<input type="text" name="mtext" size="66">
留言內(nèi)容:<textarea name="mnote" cols="64" rows="10" class="wenbenkuang"></textarea>
<input name="Button" type="button" class="btn_grey" value="提交"
onClick="check(form1)">
<input name="Submit2" type="reset" class="btn_grey" value="重置">
</form>
相關(guān)文章
IE不支持option的display樣式,只能使用remove和add
想實(shí)現(xiàn)一個(gè)很簡(jiǎn)單的功能:當(dāng)選中“中介”時(shí),不顯示“求購”與“求租”。本以為通過display:none即可實(shí)現(xiàn),結(jié)果發(fā)現(xiàn)在option元素上使用display:none在firefox中有效,在IE6、IE7、IE8中都無效。2009-12-12JavaScript關(guān)于select的相關(guān)操作說明
JavaScript關(guān)于select的相關(guān)操作參考代碼。2010-01-01js動(dòng)態(tài)在form上插入enctype=multipart/form-data的問題
在做文件上傳的時(shí)候碰到了一個(gè)比較奇怪的問題,IE6,7,8上傳文件總是失敗,服務(wù)端接收不到文件的問題2012-05-05輸入文字自動(dòng)變化寬度的INPUT,帶計(jì)數(shù)(圖)
隨著輸入文字的多少自動(dòng)變化寬度的INPUT,帶計(jì)數(shù)2008-11-11javascript實(shí)現(xiàn)的左右選擇框效果代碼
javascript實(shí)現(xiàn)的左右選擇框效果代碼...2007-10-10