国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 語(yǔ)言 > JavaScript > 正文

JS簡(jiǎn)單表單驗(yàn)證功能完整示例

2024-05-06 15:43:56
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例講述了JS簡(jiǎn)單表單驗(yàn)證功能。分享給大家供大家參考,具體如下:

簡(jiǎn)單js表單驗(yàn)證demo

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head>  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">  <title>Document</title>  <script>    //當(dāng)用戶名獲取焦點(diǎn)時(shí)    function focus_username(){      document.getElementById("user_res").innerHTML="<font color='#f00'>請(qǐng)輸入用戶名</font>";    }    //當(dāng)用戶名失去焦點(diǎn)時(shí)    function blur_username(){      var user_value=document.getElementsByName("username")[0].value;      if(user_value.length===0){      document.getElementById("user_res").innerHTML="<font color='#f00'>你沒(méi)有輸入用戶名</font>";          return false;          //判斷其長(zhǎng)度是否在5~18之間 如果不在就提示用戶      }else if(user_value.length<5||user_value.length>18)      {      document.getElementById("user_res").innerHTML="<font color='#f00'>用戶名長(zhǎng)度必須在5-18之間</font>";          return false;      }else if(!checkUser(user_value)){        //用戶名還有特殊符號(hào)      document.getElementById("user_res").innerHTML="<font color='#f00'>用戶名含有特殊符號(hào)</font>";          return false;      }else{        //用戶名合法      document.getElementById("user_res").innerHTML="<font color='#00f'>用戶名合法</font>";          return true;      }    }    //密碼獲取焦點(diǎn)時(shí)    function focus_password(){      document.getElementById("pass_res").innerHTML="<font color='#f00'>請(qǐng)輸入密碼</font>";    }    //密碼失去焦點(diǎn)時(shí)    function blur_password(){      var user_value=document.getElementsByName("password")[0].value;      if(user_value.length===0){      document.getElementById("pass_res").innerHTML="<font color='#f00'>你沒(méi)有輸入密碼</font>";          return false;          //判斷其長(zhǎng)度是否在5~18之間 如果不在就提示用戶      }else if(user_value.length<5||user_value.length>18)      {      document.getElementById("pass_res").innerHTML="<font color='#f00'>用密碼長(zhǎng)度必須在5-18之間</font>";          return false;      }else{        //密碼合法      document.getElementById("pass_res").innerHTML="<font color='#00f'>密碼合法</font>";          return true;      }    }     function checkUser(user){      var arr=["<",">","#","?","%"];      var arr_length=arr.length;      var user_length=user.length;      for(var i=0;i<arr_length;i++){        for(var j=0;j<user_length;j++){          if(arr[i]===user.charAt(j)){            return false;          }        }      }      //表示用戶名合法       return true;     }     //提交提交表單驗(yàn)證     function checkForm(){      var user_flag=blur_username();      var pass_flag=blur_password();      if(user_flag && pass_flag){        alert("提交合法表單");         return true;      }else{        alert("輸入不合法");        return false;      }     }  </script></head><body>                          <!--action 參數(shù)自定義跳轉(zhuǎn)頁(yè)面-->  <form name='form1' onsubmit='return checkForm()' action='index.php'>    <table width='600' align='center'>      <tr>        <td align='right' width='150'>用戶名:</td>        <td width='100'><input type='text' name='username' onfocus='focus_username()' onblur = 'blur_username()'/></td>        <td><span id="user_res"></span></td>      </tr>      <tr>        <td align='right' width='100'>密碼:</td>        <td width='100'><input type='password' name='password' onfocus='focus_password()' onblur = 'blur_password()'/></td>        <td><span id="pass_res"></span></td>      </tr>      <tr>        <td></td>        <td><input type='submit' value='提交' /></td>      </tr>    </table>  </form></body></html>            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 寿阳县| 阳谷县| 孟连| 林甸县| 临洮县| 卢氏县| 噶尔县| 兰西县| 东安县| 阿拉善左旗| 广昌县| 斗六市| 惠东县| 遂宁市| 墨竹工卡县| 滨海县| 凤冈县| 台南县| 张掖市| 阜平县| 城市| 镇坪县| 句容市| 任丘市| 鸡泽县| 通山县| 博兴县| 临清市| 禹城市| 蕉岭县| 新乡县| 宝应县| 安平县| 青海省| 邢台市| 绥棱县| 荔浦县| 大荔县| 湟中县| 鹤庆县| 灵寿县|