js校驗(yàn)表單后提交表單的三種方法總結(jié)
第一種:
<script type="text/javascript">
function check(form) {
if(form.userId.value=='') {
alert("請輸入用戶帳號!");
form.userId.focus();
return false;
}
if(form.password.value==''){
alert("請輸入登錄密碼!");
form.password.focus();
return false;
}
return true;
}
</script>
<form action="login.do?act=login" method="post">
用戶帳號
<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("請輸入用戶帳號!");
form.userId.focus();
return false;
}
if(form.password.value==''){
alert("請輸入登錄密碼!");
form.password.focus();
return false;
}
return true;
}
</script>
<form action="login.do?act=login" method="post" onsubmit="return check(this)">
用戶帳號
<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("請輸入用戶帳號!");
form.userId.focus();
return false;
}
if(form.password.value==''){
alert("請輸入登錄密碼!");
form.password.focus();
return false;
}
document.myform.submit();
}
</script>
<form action="login.do?act=login" name="myform" method="post">
用戶帳號
<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)文章
基于javascript實(shí)現(xiàn)九九乘法表
這篇文章主要為大家詳細(xì)介紹了基于javascript實(shí)現(xiàn)九九乘法表的相關(guān)資料,感興趣的小伙伴們可以參考一下2016-03-03
JS獲取本周周一,周末及獲取任意時(shí)間的周一周末功能示例
這篇文章主要介紹了JS獲取本周周一,周末及獲取任意時(shí)間的周一周末功能,結(jié)合實(shí)例形式分析了js通過擴(kuò)展實(shí)現(xiàn)針對日期的運(yùn)算相關(guān)技巧,需要的朋友可以參考下2017-02-02
JavaScript實(shí)現(xiàn)的文本框placeholder提示文字功能示例
這篇文章主要介紹了JavaScript實(shí)現(xiàn)的文本框placeholder提示文字功能,涉及javascript事件響應(yīng)及頁面元素屬性動態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-07-07
微信小程序?qū)崿F(xiàn)上傳照片代碼實(shí)例解析
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)上傳照片代碼實(shí)例解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08
UniApp使用vue.config.js進(jìn)行配置的詳細(xì)教程
這篇文章主要給大家介紹了關(guān)于UniApp使用vue.config.js進(jìn)行配置的詳細(xì)教程,uniapp是一套基于Vue語法的框架,同樣也支持Vue.config.js配置,一般常用的莫過于路徑的名稱,需要的朋友可以參考下2023-10-10
JavaScript中時(shí)間日期函數(shù)new?Date()詳解(5種獲取時(shí)間戳的函數(shù))
這篇文章主要給大家介紹了關(guān)于JavaScript中時(shí)間日期函數(shù)new?Date()的相關(guān)資料,主要講的是JS中5種獲取時(shí)間戳的函數(shù),new Date()是JavaScript中用于獲取當(dāng)前日期和時(shí)間的內(nèi)置函數(shù),需要的朋友可以參考下2024-04-04
通過實(shí)例了解Render Props回調(diào)地獄解決方案
這篇文章主要介紹了通過實(shí)例了解Render Props回調(diào)地獄解決方案,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11
JavaScript實(shí)現(xiàn)多文件下載方法解析
這篇文章主要介紹了JavaScript實(shí)現(xiàn)多文件下載方法解析,文章通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08

