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

jQuery實(shí)現(xiàn)驗(yàn)證碼功能

 更新時(shí)間:2017年03月17日 15:28:56   作者:18301695170  
本文主要介紹了jQuery實(shí)現(xiàn)驗(yàn)證碼功能的示例代碼,具有很好的參考價(jià)值,下面跟著小編一起來看下吧

效果圖:

代碼如下:

<!doctype html>
<html lang="en">
 <head>
 <meta charset="UTF-8">
 <title>Document</title>
 <style type="text/css">
 #code{
 width:80px;
 height:30px;
 font-size:20px;
 font-family:Arial; 
 font-style:italic; 
 font-weight:bold; 
 border:0; 
 letter-spacing:2px; 
 color:blue; 
 }
 </style>
 </head>
 <body>
<div> 
 <input type = "text" id = "input"/> 
 <input type = "button" id="code" /> 
 <input type = "button" value = "驗(yàn)證" id="check"/> 
   </div> 
 <script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
<script type="text/javascript">
  function change(){
    code=$("#code");
  // 驗(yàn)證碼組成庫
   var arrays=new Array( 
       '1','2','3','4','5','6','7','8','9','0',
       'a','b','c','d','e','f','g','h','i','j', 
       'k','l','m','n','o','p','q','r','s','t', 
       'u','v','w','x','y','z', 
       'A','B','C','D','E','F','G','H','I','J', 
       'K','L','M','N','O','P','Q','R','S','T', 
       'U','V','W','X','Y','Z'        
       ); 
    codes='';// 重新初始化驗(yàn)證碼
   for(var i = 0; i<4; i++){
   // 隨機(jī)獲取一個(gè)數(shù)組的下標(biāo)
   var r = parseInt(Math.random()*arrays.length);
   codes += arrays[r];
  }
  // 驗(yàn)證碼添加到input里
     code.val(codes);
  }
  change();
 code.click(change);
 //單擊驗(yàn)證
  $("#check").click(function(){
   var inputCode = $("#input").val().toUpperCase(); //取得輸入的驗(yàn)證碼并轉(zhuǎn)化為大寫 
   console.log(inputCode);
  if(inputCode.length == 0) { //若輸入的驗(yàn)證碼長度為0
   alert("請輸入驗(yàn)證碼!"); //則彈出請輸入驗(yàn)證碼
  }    
  else if(inputCode!=codes.toUpperCase()) { //若輸入的驗(yàn)證碼與產(chǎn)生的驗(yàn)證碼不一致時(shí)
   alert("驗(yàn)證碼輸入錯(cuò)誤!請重新輸入"); //則彈出驗(yàn)證碼輸入錯(cuò)誤
   change();//刷新驗(yàn)證碼
   $("#input").val("");//清空文本框
  }else { //輸入正確時(shí)
   alert("正確"); //彈出^-^
  } 
  });
</script>
 </body>
</html>

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論