最新消息:本站所有跳转向bbs.ykit.cn的附件将全面停止,附件已转移到https://www.qingsj.com

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

jquery 有客 340浏览

代码如下:

<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;"/>

转载请注明:有客帮 » jquery实现 字母(大小写)数字生成随机密码