js校驗(yàn)表單后提交表單的三種方法總結(jié)
第一種:
<script type="text/javascript">
function check(form) {
if(form.userId.value=='') {
alert("請(qǐng)輸入用戶(hù)帳號(hào)!");
form.userId.focus();
return false;
}
if(form.password.value==''){
alert("請(qǐng)輸入登錄密碼!");
form.password.focus();
return false;
}
return true;
}
</script>
<form action="login.do?act=login" method="post">
用戶(hù)帳號(hào)
<input type=text name="userId" size="18" value="" >
<br>
登錄密碼
<input type="password" name="password" size="19" value=""/>
<input type=submit name="submit1" value="登陸" onclick="return check(this.form)">
</form>
第二種
<script type="text/javascript">
function check(form) {
if(form.userId.value=='') {
alert("請(qǐng)輸入用戶(hù)帳號(hào)!");
form.userId.focus();
return false;
}
if(form.password.value==''){
alert("請(qǐng)輸入登錄密碼!");
form.password.focus();
return false;
}
return true;
}
</script>
<form action="login.do?act=login" method="post" onsubmit="return check(this)">
用戶(hù)帳號(hào)
<input type=text name="userId" size="18" value="" >
<br>
登錄密碼
<input type="password" name="password" size="19" value=""/>
<input type=submit name="submit1" value="登陸">
</form>
第三種:
<script type="text/javascript">
function check(form) {
if(form.userId.value=='') {
alert("請(qǐng)輸入用戶(hù)帳號(hào)!");
form.userId.focus();
return false;
}
if(form.password.value==''){
alert("請(qǐng)輸入登錄密碼!");
form.password.focus();
return false;
}
document.myform.submit();
}
</script>
<form action="login.do?act=login" name="myform" method="post">
用戶(hù)帳號(hào)
<input type=text name="userId" size="18" value="" >
<br>
登錄密碼
<input type="password" name="password" size="19" value=""/>
<input type=button name="submit1" value="登陸" onclick="check(this.form)">
</form>
相關(guān)文章
解決layui追加或者動(dòng)態(tài)修改的表單元素“沒(méi)效果”的問(wèn)題
今天小編就為大家分享一篇解決layui追加或者動(dòng)態(tài)修改的表單元素“沒(méi)效果”的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09Webpack中l(wèi)oader打包各種文件的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于Webpack中l(wèi)oader打包各種文件的相關(guān)資料,其中包括處理css文件、less文件、scss文件、url地址以及ES6高級(jí)語(yǔ)法的方法,需要的朋友可以參考下2019-09-09JavaScript實(shí)現(xiàn)基礎(chǔ)排序算法的示例詳解
這篇文章主要為大家詳細(xì)介紹了如何利用JavaScript實(shí)現(xiàn)基礎(chǔ)排序算法,如:冒泡排序、選擇排序、插入排序和快速排序,感興趣的可以了解一下2022-06-06IE6-8中Date不支持toISOString的修復(fù)方法
這篇文章主要介紹了IE6-8中Date不支持toISOString的修復(fù)方法,需要的朋友可以參考下2014-05-05TypeScript?Pinia實(shí)戰(zhàn)分享(Vuex和Pinia對(duì)比梳理總結(jié))
這篇文章主要介紹了TypeScript?Pinia實(shí)戰(zhàn)分享(Vuex和Pinia對(duì)比梳理總結(jié)),今天我們?cè)賮?lái)實(shí)戰(zhàn)下官方推薦的新的vue狀態(tài)管理工具Pini,感興趣的小伙伴可以參考一下2022-06-06JavaScript實(shí)現(xiàn)表格表單的隨機(jī)選擇和簡(jiǎn)單的隨機(jī)點(diǎn)名
本文主要介紹了JavaScript實(shí)現(xiàn)表格表單的隨機(jī)選擇和簡(jiǎn)單的隨機(jī)點(diǎn)名,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08