[JavaScript] 验证码 →→→→→进入此内容的聊天室

来自 , 2021-04-23, 写在 JavaScript, 查看 145 次.
URL http://www.code666.cn/view/1a5b1e4d
  1. <html>
  2.         <head>
  3.                 <meta charset="UTF-8">
  4.                 <title>验证码</title>
  5.                 <script type="text/javascript" src="js/jquery-1.7.2.js" ></script>
  6.                 <style>
  7.                         #code{
  8.                                 color:blue;
  9.                                 font-size:30px;
  10.                                 font-weight:bolder;
  11.                                 cursor:pointer;
  12.                                 text-align:center;
  13.                         }
  14.                 </style>
  15. <body>
  16.         <div>
  17.                 <p>验证码</p>
  18.                         <div>
  19.                                 <input type="text" id="inputcode" onblur="judge()" style="margin-top: 10px;"/>
  20.                                 <span style="background-color: yellow;" id="code" onclick="create()"></span>
  21.                         </div>
  22.         </div>
  23. </body>
  24.  
  25. <script type="text/javascript">
  26.                
  27.                 $(function(){
  28.                         create();
  29.                 });
  30.                 var code;
  31.                
  32.                 var create = function(){
  33.                         code="";
  34.                         var codeLength=6;
  35.                         var code_array = new Array(0,1,2,3,4,5,6,7,8,9,
  36.                         'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
  37.                         'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  38.                         'w', 'x', 'y', 'z','A', 'B', 'C', 'D', 'E', 'F', 'G',
  39.                         'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
  40.                         'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
  41.                        
  42.                         for(var i = 0;i<codeLength;i++){
  43.                                 var  index = Math.floor(Math.random() * 62);
  44.                                 code+=code_array[index];
  45.                         }
  46.                         $("#code").html(code);
  47.                 }
  48.                
  49.                 var judge = function(){
  50.                         var inputcode = $("#inputcode").val();
  51.                         if(inputcode == code){
  52.                                 alert("OK")
  53.                         }else{
  54.                                 alert("NO")
  55.                                 create();
  56.                         }
  57.                 }
  58.         </script>
  59. </html>

回复 "验证码"

这儿你可以回复上面这条便签

captcha