jquery生成随机密码 [字母(大小写),数字]

jquery实现 字母(大小写)数字生成随机密码

代码如下 :

<script src="http://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script>//在线链接
<script type="text/javascript">
  $(document).ready(function() {
    
    
    $('#get_pwd').click(function(){
    
    
      var str = 'mnbvcxzasdfghj0123klpoiuytrewq678MNBVCXZLKJH45GFDSAPOIUYT9REWQ';//字符串  
      var len = str.length;//查询字符串长度  
      var num=8;           //生成字符串长度
    var code = '';
    for (var i = 0; i < num; i++) {
    
    
      var rand = Math.ceil(Math.random()*len - 1);
      //console.log(rand)
        code+= str[rand];
    }
    $('#user_pws').val(code);//写入指定 input 框
    });
})
 </script>

使用方法 :

//例
 <input type="button" value="随机密码" id="get_pwd"  style="cursor: pointer;"/>

如上所示 , 为该节点添加 id 即可 (完)


猜你喜欢

转载自blog.csdn.net/qq_42961790/article/details/101779629