生成随机验证码

 1 <!doctype html>
 2 <html>
 3 <head>
 4 <meta charset="utf-8"/>
 5 <title>js验证码</title>
 6 <style type="text/css">
 7  #login{
 8     width:50px;
 9     height:30px;
10     line-height:30px;
11     margin:0 auto;
12     background-color:#eee;
13     text-align:center;
14     color:red;
15  }
16  p{
17     width:75px;
18     height:30px;
19 
20     margin:0 auto;
21  }
22     
23 </style>
24 </head>
25 <body>
26 <p>验证码:</p>
27 <div id="login" onclick="show()"><a href="#"></a></div>
28 <script type="text/javascript">
29     function codes(n){
30             var a="azxcvbnmsdfghjklqwertyuiopZXCVBNMASDFGHJKLQWERTYUIOP0123456789";
31             var b="";
32         for (var i = 0;i<n;i++){
33             var index=Math.floor(Math.random()*62);
34              b+=a.charAt(index);
35 
36         }
37         return b;
38         };
39         function show(){
40             document.getElementById("login").innerHTML=codes(4);
41        
42    }
43    window.onload=show;
44 
45 
46 </script>
47 
48 </body>
49 </html>

 

posted @ 2016-09-29 11:43  喔喔牛在路上  阅读(82)  评论(0编辑  收藏  举报