Unique codes

[JS recently re-look at the basis of summarizing some good code I hope to give you a reference]

document.getElementById code = var ( "code"); 
function the getCode () {
// Prepare a 62 string;
// generating a random number; random number can be used as an index of characters;
// random index range [0-61]
STR = var "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
// random number;
var I = 0;
var newStr = "";
the while (I <. 4) {
var NUM = Math.round (Math.random () * (61-0) +0 );
var curStr STR = [NUM];
// to transfer all characters after the splice caps, and get the new transfer uppercase characters, then verified;
var max = newStr.toUpperCase ();
var = curStr.toUpperCase maxnew ();
IF (max.indexOf (maxnew) === -. 1) {
newStr + STR = [NUM];
I ++;
}
}
= newStr code.innerHTML;
}
the getCode ();
// the address space assigned to the function code of the onclick attribute;
code.onclick = the getCode;

Guess you like

Origin www.cnblogs.com/supershare/p/12106518.html