demo1.html
<html> <fead> <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 == "" ") {alerta (" 当前表单不能有空项 "); document.Form1.Elements [i] .focus (); devolver falso; }} return verdadero; } </script> </head> <body> <form de nombre = "form1" método = "post" action = "page2.html" onSubMit = "return myCheck ()"> 用户名: <input type = "text" name = "username"> <br> 性别: <input type = "text" name = "sex"> <br> 出生时间: <input type = "text" name = "name" birthday "<briT" <briT ">" Subt "<BRIt" value = "提交"> </form> </body> </html> Demo2.html <script language = "javascript"> <!-function Subt1 (frm) {if (document.frm.word.value == "") Action = "" name = "frm" onSubMit = "return Submit1 (this);"> <select name = "select0"> <opción value = "0"> 请选择一个类别 </opción> <opción valor valor = "1"> 新闻 </opción> <opción valor = "2"> 产品 </opción> <opción valor = "3"> 留言 </select> <select> <input type = "Nombre de texi" " style = "Height: 19px;"> <input type = "radio" name = "sea_cat" value = "标题"> 标题 <input type = "radio" name = "sea_cat" valor = "内容"> 内容 <input type = "enviar" valor = "搜" name = "b1">>demo3.html
<script type = "text/javaScript"> function befeforesubmit (form) {if (form.username.value == '') {alert ('用户名不能为空!'); form.username.focus (); return false;} if (form.password.value == '' ') {alerta (' 密码不能为空! '); Form.password.focus (); false;} if (form.password.value.length <6) {alert ('密码至少为 6 位 , 请重新输入!'); form.password.focus (); return false;} if (form.password.value! = form.password2.value) {alert ('你两次输入的密码不一致 ,' '); form.password2.focus (); return false;} true;} </script> <scieldset> <legend> 用户注册 </legend> <form de método = "post" name = "form" action = "user.do?method=register" onsubMit = "return befefefefefefifeSubMit (this);"> <table cellspacing = "0" cellpadding = "0"> <t> <Td> <label> 用户名 ~ <inying type = "text" " name = "UserName" Valor = ""> </selebel> </td> </tr> <tr> <tr> <td> <label> <tr> <td> <input value = "注册" type = "enviar"> <input type = "reset" value = "重置"> </td> </tr> </table> </form> </fieldset>以上这篇 JS 判断所有表单项不为空则提交表单的实现方法就是小编分享给大家的全部内容了 , 希望能给大家一个参考 也希望大家多多支持武林网。