js校驗表單后提交表單的三種方法總結
第一種:
<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>
相關文章
解決layui追加或者動態(tài)修改的表單元素“沒效果”的問題
今天小編就為大家分享一篇解決layui追加或者動態(tài)修改的表單元素“沒效果”的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09Webpack中l(wèi)oader打包各種文件的方法實例
這篇文章主要給大家介紹了關于Webpack中l(wèi)oader打包各種文件的相關資料,其中包括處理css文件、less文件、scss文件、url地址以及ES6高級語法的方法,需要的朋友可以參考下2019-09-09TypeScript?Pinia實戰(zhàn)分享(Vuex和Pinia對比梳理總結)
這篇文章主要介紹了TypeScript?Pinia實戰(zhàn)分享(Vuex和Pinia對比梳理總結),今天我們再來實戰(zhàn)下官方推薦的新的vue狀態(tài)管理工具Pini,感興趣的小伙伴可以參考一下2022-06-06JavaScript實現(xiàn)表格表單的隨機選擇和簡單的隨機點名
本文主要介紹了JavaScript實現(xiàn)表格表單的隨機選擇和簡單的隨機點名,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-08-08