循環讀取文本框數組

<script type="text/javascript">
var checkForm = function(){
var fmElements = document.forms["fm"].elements;
for(var i=0; i<fmElements.length; i++){
if(fmElements[i].value.length < 1){
alert(fmElements[i].name+"不能爲空");
fmElements[i].focus();
return;
}
}
}
</script>
<form id="fm">
<input type="text" name="textfield0" size="30" />
<input type="text" name="textfield1" size="30" />
<input type="text" name="textfield2" size="30" />
<input type="text" name="textfield3" size="30" />
<input type="button" value="提交" οnclick="checkForm();" />
</form> 

 
發佈了11 篇原創文章 · 獲贊 3 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章