HTML form表單提交方法案例詳解
form表單提交方式總結(jié)一下:
一、利用submit按鈕實(shí)現(xiàn)提交,當(dāng)點(diǎn)擊submit按鈕時,觸發(fā)onclick事件,由JavaScript里函數(shù)判斷輸入內(nèi)容是否為空,如果為空,返回false, 不提交,如果不為空,提交到由action指定的地址。
<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>
二、利用button按鈕實(shí)現(xiàn)提交,當(dāng)點(diǎn)擊button按鈕時,觸發(fā)onclick事件,由JavaScript里函數(shù)判斷輸入內(nèi)容是否為空,如果為空,返回false, 不提交,如果不為空,提交到由action指定的地址,由于button按鈕不具備自動提交的功能,所以由JavaScript實(shí)現(xiàn)提交。
<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>
三、利用submit按鈕實(shí)現(xiàn)提交,當(dāng)點(diǎn)擊submit按鈕時,先觸發(fā)onsubmit事件,由JavaScript里函數(shù)判斷輸入內(nèi)容是否為空,如果為空,返回false, 不提交,如果不為空,提交到由action指定的地址。
<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>
以上就是form表單常用的三種提交方式,有不明白的地方,歡迎qq交流:317856821
到此這篇關(guān)于HTML form表單提交方法案例詳解的文章就介紹到這了,更多相關(guān)HTML form表單提交內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JavaScript預(yù)解析之變量預(yù)解析和函數(shù)預(yù)解析
這篇文章主要介紹了JavaScript預(yù)解析之變量預(yù)解析和函數(shù)預(yù)解析的相關(guān)資料,需要的朋友可以參考下2022-07-07圖解prototype、proto和constructor的三角關(guān)系
在javascript中,prototype、constructor以及__proto__之間有著“著名”的剪不斷理還亂的三角關(guān)系,樓主就著自己對它們的淺顯認(rèn)識,來粗略地理理以備忘,有不對之處還望斧正。2016-07-07a標(biāo)簽的href和onclick 的事件的區(qū)別介紹
a標(biāo)簽的href與onclick事件,想必大家不陌生吧,至于它們有什么區(qū)別,你知道嗎?下面就為大家介紹下,感興趣的朋友可以學(xué)習(xí)下,希望對大家有所幫助2013-07-07解析DHTML,JavaScript,DOM,BOM以及WEB標(biāo)準(zhǔn)的描述
本篇文章是對DHTML,JavaScript,DOM,BOM以及WEB標(biāo)準(zhǔn)進(jìn)行了詳細(xì)的描述介紹,需要的朋友參考下2013-06-06在JS中操作時間之getUTCMilliseconds()方法的使用
這篇文章主要介紹了在JavaScript中操作時間之getUTCMilliseconds()方法的使用,是JavaScript入門學(xué)習(xí)中的基礎(chǔ)知識,需要的朋友可以參考下2015-06-06詳解javascript中var與ES6規(guī)范中l(wèi)et、const區(qū)別與用法
es6剛流行那會,我只知道var即將退出歷史舞臺,取而代之的是let和const,卻不知道var有什么缺陷,為什么會被取代。今天在網(wǎng)上看到一段視頻,解答了我的疑惑2020-01-01