看到蓝色理想论坛有朋友发帖“跪求输出0-9,a-z,A-Z的随机20个符号”
于是试着写了一个,写完想回复发现蓝色理想注册还要手机邀请码?算了!发到自己博客里:
function s20(){
var data=["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"];
var result="";
for(var i=0;i<20;i++){
var r=Math.floor(Math.random()*62); //取得0-62间的随机数,目的是以此当下标取数组data里的值!
result+=data[r]; //输出20次随机数的同时,让rrr加20次,就是20位的随机字符串了。
}
document.writeln(result);
}
结果如:4wqFdbM4vHHFpwld6QcF