标签:string += key dom nbsp max var ring def
方法:
//生成随机字符串
function randomString(len) {
len = len || 32;
/****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
var $chars = ‘ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678‘;
var maxLen = $chars.length;
var str = ‘‘;
for (i = 0; i < len; i++) {
str += $chars.charAt(Math.floor(Math.random() * maxLen));
}
return str;
}
使用:
var $res=randomString(0);
或者var $res=randomString();
console.log($res);//DQyfD3XxZdzwXEpsQyzPjE2GSGnxnkGN
标签:string += key dom nbsp max var ring def
原文地址:https://www.cnblogs.com/meiyanstar/p/12870728.html