2015-12-10 11:49:49
function getGuid() { var guid = ""; for (var i = 1; i <= 32; i++){ var flag = Math.floor(Math.random() * 10); //如果是偶数就设置成为 if(flag%2 == 0) { //全大写 var n = Math.floor(flag*2.4) + 65; //全小写 // var n = Math.floor(flag*2.4) + 97; var n = String.fromCharCode(n); guid += n; } else { guid += flag; } // if((i==8)||(i==12)||(i==16)||(i==20)) // guid += "-"; } return guid; } console.log(getGuid()); //获取字符 var a = 98; console.log(String.fromCharCode(a)); //获取编码 var code = 'ABCDEFG'; console.log(code.charCodeAt(0) + ',' + code.charCodeAt(1));