• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
    當前位置: 首頁 - 科技 - 知識百科 - 正文

    JavaScript 完成注冊頁面表單校驗的實例

    來源:懂視網 責編:小采 時間:2020-11-27 22:32:16
    文檔

    JavaScript 完成注冊頁面表單校驗的實例

    JavaScript 完成注冊頁面表單校驗的實例:1、步驟分析 第一步:確定事件(onsubmit)并為其綁定一個函數 第二步:書寫這個函數(獲取用戶輸入的數據<獲取數據時需要在指定位置定義一個 id>) 第三步:對用戶輸入的數據進行判斷 第四步:數據合法(讓表單提交) 第五步:數據非法(給出錯誤提示信息
    推薦度:
    導讀JavaScript 完成注冊頁面表單校驗的實例:1、步驟分析 第一步:確定事件(onsubmit)并為其綁定一個函數 第二步:書寫這個函數(獲取用戶輸入的數據<獲取數據時需要在指定位置定義一個 id>) 第三步:對用戶輸入的數據進行判斷 第四步:數據合法(讓表單提交) 第五步:數據非法(給出錯誤提示信息

    1、步驟分析

    第一步:確定事件(onsubmit)并為其綁定一個函數

    第二步:書寫這個函數(獲取用戶輸入的數據<獲取數據時需要在指定位置定義一個 id>)

    第三步:對用戶輸入的數據進行判斷

    第四步:數據合法(讓表單提交)

    第五步:數據非法(給出錯誤提示信息,不讓表單提交)

    問題:如何控制表單提交?

    關于事件 onsubmit:一般用于表單提交的位置,那么需要在定義函數的時候給出一個 返回值。

    onsubmit = return checkForm()

    2、完成注冊頁面表單校驗

    <!DOCTYPE html>
    <html>
     <head>
     <meta charset="UTF-8">
     <title>注冊頁面</title>
     <script>
     function checkForm(){
     //alert("aa");
     
     /**校驗用戶名*/
     //1.獲取用戶輸入的數據
     var uValue=document.getElementById("user").value;
     //alert(uValue);
     if(uValue==""){
     //2.給出錯誤提示信息
     alert("用戶名不能為空");
     return false;
     }
     
     /**校驗密碼*/
     var pValue=document.getElementById("password").value;
     if(pValue==""){ //注意空的表示方法
     alert("密碼不能為空");
     return false;
     }
     
     /** 校驗確認密碼*/
     var rpValue=document.getElementById("repassword").value;
     if(rpValue!=pValue){
     alert("兩次密碼輸入不一致!");
     return false;
     }
     
     /**校驗郵箱*/
     var eValue=document.getElementById("email").value;
     if(!/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(eValue)){
     alert("郵箱格式不正確!");
     }
     }
     </script>
     </head>
     <body>
     <table border="1px" align="center" width="1300px" cellpadding="0px" cellspacing="0px">
     
     <!--1.logo部分-->
     <tr>
     <td>
     <!--嵌套一個一行三列的表格-->
     <table border="1px" width="100%">
     <tr height="50px">
     <td width="33.3%">
     <img src="../img/logo2.png" height="47px" />
     </td>
     <td width="33.3%">
     <img src="../img/header.png" height="47px"/>
     </td>
     <td width="33.3%">
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >登錄</a>
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >注冊</a>
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >購物車</a>
     </td>
     </tr>
     </table>
     </td>
     </tr>
     
     <!--2.導航欄部分-->
     <tr height="50px" >
     <td bgcolor="black">
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><font size="3" color="white">首頁</font></a>        
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><font color="white">手機數碼</font></a>        
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><font color="white">電腦辦公</font></a>       
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><font color="white">鞋靴箱包</font></a>       
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><font color="white">家用電器</font></a>
     </td>
     </tr>
     
     <!--3.注冊表單-->
     <tr>
     <td height="600px" background="../img/regist_bg.jpg">
     <!--嵌套一個十行二列的表格-->
     <form action="#" method="get" name="regForm" onsubmit="return checkForm()">
     <table border="1px" width="750px" height="400px" align="center" cellpadding="0px" cellspacing="0px" bgcolor="white">
     <tr height="40px">
     <td colspan="2">
     <font size="4">會員注冊</font>   USER REGISTER
     </td>
     </tr>
     <tr>
     <td>用戶名</td>
     <td>
     <input type="text" name="user" size="35px" id="user"/>
     </td>
     </tr>
     <tr>
     <td>密碼</td>
     <td>
     <input type="password" name="password" size="35px" id="password"/>
     </td>
     </tr>
     <tr>
     <td>確認密碼</td>
     <td>
     <input type="password" name="repassword" size="35px" id="repassword"/>
     </td>
     </tr>
     <tr>
     <td>E-mail</td>
     <td>
     <input type="text" name="e-mail" size="35px" id="email"/>
     </td>
     </tr>
     <tr>
     <td>姓名</td>
     <td>
     <input type="text" name="username" size="35px"/>
     </td>
     </tr>
     <tr>
     <td>性別</td>
     <td>
     <input type="radio" name="sex" value="男"/>男
     <input type="radio" name="sex" value="女"/>女
     </td>
     </tr>
     <tr>
     <td>出生日期</td>
     <td>
     <input type="text" name="birthday" size="35px"/>
     </td>
     </tr>
     <tr>
     <td>驗證碼</td>
     <td>
     <input type="text" name="yzm" />
     <img src="../img/yanzhengma.png" />
     </td>
     </tr>
     <tr align="center">
     <td colspan="2">
     <input type="submit" value="注冊" />
     </td>
     </tr>
     </table>
     </form>
     </td>
     </tr>
     
     <!--4.廣告圖片-->
     <tr>
     <td>
     <img src="../img/footer.jpg" width="100%"/>
     </td>
     </tr>
     
     <!--5.友情鏈接和版權信息-->
     <tr>
     <td align="center">
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><font>關于我們</font></a>
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><font>聯系我們</font></a>
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><font>招賢納士</font></a>
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><font>法律聲明</font></a>
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><font>友情鏈接</font></a>
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><font>支付方式</font></a>
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><font>配送方式</font></a>
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><font>服務聲明</font></a>
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><font>廣告聲明</font></a>
     <p>
     Copyright © 2005-2016 hh商城 版權所有 
     </p>
     </td>
     </tr>
     </table>
     </body>
    </html>

    在校驗確認密碼這部分使用了正則表達式(不需要記憶,需要時查找文檔)

    正則式.test(校驗對象)為真表示符合條件,為假則不符合。

    以上這篇JavaScript 完成注冊頁面表單校驗的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

    聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    JavaScript 完成注冊頁面表單校驗的實例

    JavaScript 完成注冊頁面表單校驗的實例:1、步驟分析 第一步:確定事件(onsubmit)并為其綁定一個函數 第二步:書寫這個函數(獲取用戶輸入的數據<獲取數據時需要在指定位置定義一個 id>) 第三步:對用戶輸入的數據進行判斷 第四步:數據合法(讓表單提交) 第五步:數據非法(給出錯誤提示信息
    推薦度:
    標簽: 注冊 判斷 js
    • 熱門焦點

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 国产精品精品自在线拍| 亚洲精品国产av成拍色拍| 欧美 日韩 精品 另类视频| 国产国产精品人在线视| 久热精品人妻视频| 99久久精品国产综合一区| 国产产无码乱码精品久久鸭| 亚洲欧美日韩国产精品| 国自产精品手机在线观看视频| 国产精品久久精品| 国产精品亚洲A∨天堂不卡| 欧美久久久久久午夜精品| 国产精品亚洲w码日韩中文| 国产精品一区二区久久精品| 四虎成人精品无码| 亚洲精品无码专区2| 欧美国产精品va在线观看| 国产精品99久久不卡| 欧美精品天天操| 国产日韩精品在线| 国产精品素人搭讪在线播放| 99精品一区二区三区无码吞精| 国产精品亚洲а∨无码播放| 精品人人妻人人澡人人爽人人| 亚洲AV无码精品无码麻豆| 亚洲精品偷拍视频免费观看| 亚洲国产精品成人久久蜜臀 | 国产精品兄妹在线观看麻豆| 在线精品国产一区二区三区| 日韩精品无码Av一区二区| 色婷婷久久久SWAG精品| 天天爽夜夜爽夜夜爽精品视频| 欧美国产精品va在线观看| 日韩精品一区二区三区在线观看| 免费视频精品一区二区| 欧美人与性动交α欧美精品| 欧美成人精品一区二区综合| 亚洲欧美精品一区久久中文字幕| 亚洲国产精品一区二区久久hs| 中文无码久久精品| 麻豆亚洲AV永久无码精品久久 |