复制代码 代码如下: //检查表单元素是否为空 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(); } 调用 <form name="form1" method="post" action=""> 留 言 人:<input type="text" name="mname" size="20"> 留言主题:<input type="text" name="mtext" size="66"> 留言内容:<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>
推荐阅读
javascript日期转换 时间戳转日期格式
复制代码 代码如下: Date.prototype.format = function(format) { var o = { "M+" : this.getMonth()+1, //month "d+" : this.getDate(), //day "h+" : this.getHours(), //hour "m+" : this.getMinutes(), //minu>>>详细阅读
本文标题:js Form.elements[i]的使用实例
地址:http://www.17bianji.com/kaifa2/JS/23918.html
1/2 1