Demo1.html
<html> <éad- head> <ititle> 提交表单页 </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 (); retourne false; }} return true; } </ script> </ head> <body> <form name = "form1" metheth = "post" action = "page2.html" onSubmit = "return mycheck ()"> 用户名: <entrée type = "text" name = "username"> <br> 性别: <entrée type = "text" name = "sex"> <br> 出生时间: <puty type = "text" name = "anniversaire"> <br> <br> 出生时间: <put type = "text" Value = "提交"> </ form> </ body> </html> Demo2.html <Script Language = "JavaScript"> <! - Fonction Soumis1 (frm) {if (document.frm.word.value == "") {alert ("请输入搜索新闻内容!"); action = "" name = "frm" onsubmit = "return soumed1 (this);"> <select name = "select0"> <option value = "0"> 请选择一个类别 </ option> <option valeur = "1"> 新闻 </ option> <option value = "2"> 产品 </ / option> <option value = "3"> 留言 </popoption> </lect> <entrée = style = "height: 19px;"> <input type = "radio" name = "sea_cat" value = "标题"> 标题 <input type = "radio" name = "sea_cat" value = "内容"> 内容 <input type = "soume" value = "搜" name = "b1">démo3.html
<script type = "text / javascript"> function beForesUbmit (form) {if (form.username.value == '') {alert ('用户名不能为空!'); form.username.focus (); return false;} if (form.password.value == '') {alert ('密码不能为空!'); form.password. false;} if (form.password.value.length <6) {alert ('密码至少为 6 位 , 请重新输入!'); form.password.focus (); return false;} if (form.password.value! = form.password2.value) {alert ('你两次输入的密码不一致 , 请重新输入!'); form.password. true;} </cript> <fieldset> <gend> 用户注册 </gend> <form méthode = "post" name = "form" action = "user.do?Method=Register" onSubmit = "return beforesubmit (this);"> <table cellspacing = "0" cellpadding = "0"> <tr> <td> <label> Value = ""> </ Label> </td> </ Tr> <Tr> <Td> <Belle> 密 码 : <Input Type = "Password" name = "Password" Value = ""> </ Label> </ Td> </ Tr> <Tr> <Td> <Belle> 重复密码 : <puty type = "Password" name = "Passway2" Value = ""> </ Label> </ TD> value = "注册" type = "soumis"> <input type = "reset" value = "重置"> </td> </tr> </ table> </ form> </ fieldset>以上这篇 JS 判断所有表单项不为空则提交表单的实现方法就是小编分享给大家的全部内容了 , 希望能给大家一个参考 , 也希望大家多多支持武林网。