js Form.elements[i]的使用實例
更新時間:2011年11月13日 23:36:43 作者:
js Form.elements[i]的使用實例,這樣的代碼比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();
//指定表單元素獲得焦點
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
想實現(xiàn)一個很簡單的功能:當選中“中介”時,不顯示“求購”與“求租”。本以為通過display:none即可實現(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動態(tài)在form上插入enctype=multipart/form-data的問題
在做文件上傳的時候碰到了一個比較奇怪的問題,IE6,7,8上傳文件總是失敗,服務(wù)端接收不到文件的問題2012-05-05