Demo1.html
<html> <head> <title> 提交表单页 </title> <script type = "text/javascript"> function mycheck () {for (var i = 0; i <document.form1.elements.length-1; i ++) {if (document.form1.elements [i] .value == "") {alert ("当前表单不能有空项"); document.form1.elements [i] .focus (); вернуть ложь; }} вернуть true; } </script> </head> <body> <form name="form1" method="post" action="page2.html" onSubmit="return myCheck()"> 用户名:<input type="text" name="username"><br> 性别:<input type="text" name="sex"><br> 出生时间:<input type="text" name="birthday"><br> <input type="submit" value = "提交"> </form> </body> </html> demo2.html <script language = "javascript"> <!-function propect1 (frm) {if (document.frm.word.value == "") {alert ("请输入搜索新闻内容!"); document.frm.word.focus (); return;} return true; action = "" name = "frm" onsubmit = "return opper1 (this);"> <select name = "select0"> <vitue value = "0"> 请选择一个类别 </option> <vitue value = "1"> 新闻 </option> <vitue value = "2"> 产品 </option> <vitue value = "3"> 留言 antuction> </select> input type type = "name =" 20 "20". style = "height: 19px;"> <input type = "radio" name = "sea_cat" value = "标题"> 标题 <input type = "radio" name = "sea_cat" value = "内容"> 内容 <input type = "vade =" 搜 "name =" b1 ">Demo3.html
<script type = "text/javascript"> function beforesubmit (form) {if (form.username.value == '') {alert ('用户名不能为空!'); form.username.focus (); вернуть false;} if (form.password.value == '') {alert ('密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! 密码不能为空! warpsword. false;} if (form.password.value.length <6) {alert ('密码至少为 6 位 , 请重新输入!'); form.password.focus (); вернуть false;} if (form.password.value! = form.password2.value) {alert ('你两次输入的密码不一致 , 请重新输入!'); true;} </script> <fieldset> <legend> 用户注册 </legend> <form method = "post" name = "form" action = "user.do?method=register" onsubmit = "return beforesubmit (this);"> <table cellspoging = "0" cellPadding = "0"> <TreBlemt (this); value = ""> </label> </td> </tr> <tr> <td> <babel> 密 码 : <input type = "password" name = "password" value = ""> </label> </td> </tr> <tr> <td> <babel> : hope = "password" name = " <tr> <td> <input value = "注册" type = "opper"> <input type = "reset" value = "重置"> </td> </tr> </table> </form> </fieldset>以上这篇 JS 判断所有表单项不为空则提交表单的实现方法就是小编分享给大家的全部内容了 希望能给大家一个参考 , 也希望大家多多支持武林网。