随机生成字符串
代码:
//
var pwd;
// 点击生成随机数 10位
$('.random').click(function () {
pwd = ""; //点击重置字段
var pwdLength = 10;//密码的长度
var random = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');//随机数
for (var i = 0; i < pwdLength; i++) {//循环操作
var index = Math.floor(Math.random() * 62);//取得随机数的索引(0~61)
pwd += random[index];//根据索引取得随机数加到pwd上
}
//把pwd 值赋给验证码
$('input[name="token_key"]').val(pwd)
})