js判斷所有表單項(xiàng)不為空則提交表單的實(shí)現(xiàn)方法
更新時(shí)間:2016年09月09日 08:51:33 投稿:jingxian
下面小編就為大家?guī)硪黄猨s判斷所有表單項(xiàng)不為空則提交表單的實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的, 現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
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("當(dāng)前表單不能有空項(xiàng)");
document.form1.elements[i].focus();
return false;
}
}
return 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>
出生時(shí)間:<input type="text" name="birthday"><br>
<input type="submit" value="提交">
</form>
</body>
</html>
demo2.html
<script language="Javascript">
<!--
function submit1(frm){
if (document.frm.word.value=="") {
alert("請輸入搜索新聞內(nèi)容!");document.frm.word.focus();return false;
}
return true;
}
//-->
</script>
<form method="POST" action="" name="frm" onsubmit="return submit1(this);">
<select name="select0">
<option value="0">請選擇一個(gè)類別</option>
<option value="1">新聞</option>
<option value="2">產(chǎn)品</option>
<option value="3">留言</option>
</select>
<input type="text" name="word" size="20" class="input" style="height:19px; ">
<input type="radio" name="sea_cat" value="標(biāo)題">標(biāo)題
<input type="radio" name="sea_cat" value="內(nèi)容">內(nèi)容
<input type="submit" value="搜" name="B1" class="input1" >
demo3.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.focus();
return 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;
}
return true;
}
</script>
<fieldset>
<legend>用戶注冊</legend>
<form method="post" name="form" action="user.do?method=register" onSubmit="return beforeSubmit(this);">
<table border="1" width="100%" cellspacing="0" cellpadding="0">
<tr><td><label>用戶名:<input type="text" name="username" value=""></label></td></tr>
<tr><td><label>密 碼:<input type="password" name="password" value=""></label></td></tr>
<tr><td><label>重復(fù)密碼:<input type="password" name="password2" value=""></label></td></tr>
<tr><td><input value="注冊" type="submit"> <input type="reset" value="重置"></td></tr>
</table>
</form>
</fieldset>
以上這篇js判斷所有表單項(xiàng)不為空則提交表單的實(shí)現(xiàn)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
js無后端實(shí)現(xiàn)點(diǎn)擊加載查看更多(提示SEO友好度)
為了提示SEO友好度,并且避免調(diào)用后端接口給服務(wù)器造成負(fù)擔(dān),可以使用js無后端實(shí)現(xiàn)點(diǎn)擊加載查看更多,比如HTML中源碼存在60條記錄,預(yù)先顯示20條記錄,點(diǎn)擊“查看更多”一次追加10條,最后一次后按鈕文本改為“已查看全部”,在JavaScript中,你可以使用以下步驟來實(shí)現(xiàn)2024-10-10
uniapp基礎(chǔ)知識(shí)點(diǎn)掌握以及面試題整理
uni-app是一個(gè)使用vue.js開發(fā)所有前端應(yīng)用的框架,開發(fā)者編寫一套代碼,下面這篇文章主要給大家介紹了關(guān)于uniapp基礎(chǔ)知識(shí)點(diǎn)掌握以及面試題整理的相關(guān)資料,需要的朋友可以參考下2023-02-02
基于JS實(shí)現(xiàn)文字轉(zhuǎn)語音即文本朗讀
這篇文章主要為大家詳細(xì)介紹了JavaScript如何利用SpeechSynthesis實(shí)現(xiàn)文字轉(zhuǎn)語音即文本朗讀的功能,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-10-10
js實(shí)現(xiàn)input密碼框顯示/隱藏功能
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)input密碼框顯示和隱藏功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-10-10

