js验证不重复验证码|JS验证不重复验证码

更新时间:2021-06-17    来源:js教程    手机版     字体:

【www.bbyears.com--js教程】

 

 代码如下

 

 不重复验证码

 

 

 

 

 

 

 <script>

    function $(id){

     return document.getElementById(id);

    }

    var $useId = $('useId'),

      $txt = $('txt'),

      $btn = $('btn');

    function getStr(){

    var string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',

      str = '';

      while(str.length <6){

     varstr1=string.charAt(Math.round(Math.random() * 56));

     if(str.indexOf(str1) === -1){

      str += str1;

     }

    }

    $useId.innerHTML=str;

    }

    function checkCode(){

     if($txt.value == $useId.innerHTML){

     alert('验证成功');

     }else{

     alert('验证失败');

     }

    }

    $useId.onclick=getStr;

    $btn.onclick=checkCode;

 </script>

 

本文来源:http://www.bbyears.com/wangyezhizuo/124256.html

热门标签

更多>>

本类排行