var arr = []; for (var i = 48; i <= 57; i++) { arr.push(String.fromCharCode(i)); } console.log(arr); for (var j = 65; j <= 90; j++) { arr.push(String.fromCharCode(j)) } console.log(arr); for (var k = 97; k <= 122; k++) { arr.push(String.fromCharCode(k)) } console.log(arr); var str = ''; for (var i = 0; i < 4; i++) { var index = Math.floor(Math.random() * arr.length); //index代表下标。 //利用下标找下标对应的值 console.log(index); str += arr[index] } console.log(str);
标签:小写字母,验证码,大写字母,nG3p,随机,var From: https://www.cnblogs.com/zhaofen/p/17115753.html