h5+css+js简单验证码

白昼怎懂夜的黑 提交于 2019-12-09 09:39:08
  1. <!DOCTYPE HTML>  
  2. <html>  
  3.     <head>  
  4.         <title>EasyBuy后台管理系统</title>  
  5.         <meta charset="utf-8">  
  6.         <style>  
  7.             .main_bar{  
  8.                 width:1350px;  
  9.                 height:350px;  
  10.                 background-color:#6495ED;  
  11.                 margin-top:10%;  
  12.             }         
  13.             #login_form{  
  14.                 width:40%;  
  15.                 height:100%;  
  16.                 background-color:#112435;  
  17.                 margin:0 auto;  
  18.             }  
  19.             .title{  
  20.                 width:100%;  
  21.                 height:55px;  
  22.                 color:#ffffff;  
  23.                 border-bottom:1px solid #ffffff;  
  24.                 font-size:20pt;  
  25.                 font-family:"微软雅黑";  
  26.                 line-height:55px;  
  27.                 text-align:center;                
  28.             }  
  29.             #form_widget{  
  30.                 width:100%;  
  31.                 height:295px;  
  32.                 background-color:#808080;  
  33.             }  
  34.             .txt{  
  35.                 display:block;/*设置为独立块(换行)*/  
  36.                 width:70%;  
  37.                 margin:0 auto;  
  38.                 height:35px;  
  39.                 font-size:15pt;  
  40.                 border-radius:5px;/*设置圆角样式*/  
  41.                 border:0;  
  42.                 padding-left:8px;  
  43.             }  
  44.             #vcode{  
  45.                 height:35px;  
  46.                 width:40%;  
  47.                 font-size:15pt;  
  48.                 margin-left:15%;  
  49.                 border-radius:5px;  
  50.                 border:0;  
  51.                 padding-left:8px;  
  52.             }  
  53.             #code{  
  54.                 color:#ffffff;/*字体颜色白色*/  
  55.                 background-color:#000000;     
  56.                 font-size:20pt;  
  57.                 font-family:"华康娃娃体W5";  
  58.                 padding:5px 35px 10px 35px;  
  59.                 margin-left:5%;       
  60.                 cursor:pointer;  
  61.             }  
  62.             #search_pass_link{  
  63.                 width:70%;  
  64.                 text-align:right;  
  65.                 margin:0 auto;  
  66.                 padding:5px;  
  67.             }  
  68.             /*层级选择器*/  
  69.             #search_pass_link a{  
  70.                 color:#000000;  
  71.                 text-decoration:none;                 
  72.             }  
  73.             /*伪类*/  
  74.             #search_pass_link a:hover{  
  75.                 color:#ff0000;  
  76.                 text-decoration:underline;  
  77.             }  
  78.             .btn{  
  79.                 width:70%;  
  80.                 margin-left:15%;  
  81.                 height:40px;  
  82.                 border:0;  
  83.                 font-size:14pt;  
  84.                 font-family;"微软雅黑";  
  85.                 background-color:#FC5628;  
  86.                 color:#ffffff;  
  87.                 cursor:pointer;/*设置指针鼠标的样式*/  
  88.                 border-radius:20px;/*设置圆角样式*/  
  89.                 border:0;  
  90.             }     
  91.             #copyright{  
  92.                 width:100%;  
  93.                 text-align:center;  
  94.                 padding-top:20px;  
  95.                 font-family:"微软雅黑";  
  96.                 color:#e0e0e0;  
  97.             }  
  98.         </style>  
  99.     </head>  
  100.     <body leftmargin="0" onload="changeImg()">  
  101.         <div class="main_bar">   
  102.             <div id="login_form">  
  103.                 <div class="title">  
  104.                     EasyBuy系统登录                   
  105.                 </div>      
  106.                 <form action="main.html" onsubmit="return check()">  
  107.                 <div id="form_widget">  
  108.                     <br>  
  109.                     <input type="text" placeholder="请输入账号" id="box_name" class="txt" value="用户名" onfocus="this.value=''" onblur="if(this.value=='')this.value='用户名'"/>  
  110.                     <br>  
  111.                     <input type="password" placeholder="请输入密码" id="box_pass" class="txt" value="password" onfocus="this.value=''" onblur="if(this.value=='')this.value='password'"/>  
  112.                     <br>  
  113.                     <input type="text" id="vcode" placeholder="验证码" value="验证码" onfocus="this.value=''" onblur="if(this.value=='')this.value='验证码'"/><span id="code" title="看不清,换一张"></span>  
  114.                     <div id="search_pass_link">  
  115.                         <a href="#">忘记密码?</a>  
  116.                     </div>                      
  117.                     <input  type="submit" value="登录" class="btn" onmouseover="this.style.backgroundColor='#FF8D00'" onmouseout="this.style.backgroundColor='#FC5628'">  
  118.                     <br>  
  119.                     <div id="copyright">  
  120.                         Power By WXH &copy;CopyRight 2016  
  121.                     </div>  
  122.                 </div>  
  123.                 </form>  
  124.             </div>  
  125.         </div>      
  126.     </body>     
  127.     <script type="text/javascript">  
  128.         var code;//声明一个变量用于存储生成的验证码  
  129.         document.getElementById("code").onclick=changeImg;  
  130.         function changeImg(){  
  131.             //alert("换图片");  
  132.             var arrays=new Array(  
  133.                 '1','2','3','4','5','6','7','8','9','0',  
  134.                 'a','b','c','d','e','f','g','h','i','j',  
  135.                 'k','l','m','n','o','p','q','r','s','t',  
  136.                 'u','v','w','x','y','z',  
  137.                 'A','B','C','D','E','F','G','H','I','J',  
  138.                 'K','L','M','N','O','P','Q','R','S','T',  
  139.                 'U','V','W','X','Y','Z'               
  140.             );  
  141.             code='';//重新初始化验证码  
  142.             //alert(arrays.length);  
  143.             //随机从数组中获取四个元素组成验证码  
  144.             for(var i=0;i<4;i++){  
  145.             //随机获取一个数组的下标  
  146.                 var r=parseInt(Math.random()*arrays.length);  
  147.                 code+=arrays[r];  
  148.                 //alert(arrays[r]);  
  149.             }  
  150.             //alert(code);  
  151.             document.getElementById('code').innerHTML=code;//将验证码写入指定区域  
  152.         }         
  153.           
  154.         //效验验证码(表单被提交时触发)  
  155.         function check(){  
  156.             //获取用户输入的验证码  
  157.             var input_code=document.getElementById('vcode').value;  
  158.             //alert(input_code+"----"+code);  
  159.             if(input_code.toLowerCase()==code.toLowerCase())  
  160.             {  
  161.                 //验证码正确(表单提交)  
  162.                 return true;  
  163.             }  
  164.             alert("请输入正确的验证码!");  
  165.             //验证码不正确,表单不允许提交  
  166.             return false;  
  167.         }  
  168.     </script>   
  169. </html>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!