欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

HTML form表單提交方法案例詳解

 更新時間:2021年08月19日 16:38:26   作者:菜鳥一縷清風(fēng)  
這篇文章主要介紹了HTML form表單提交方法案例詳解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下

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)文章

最新評論