产生随机4个英文字母详情看下面代码!
<!doctype
html>
<html
lang="en">
<head>
<meta
charset="UTF-8">
</head>
<div
id="result"></div><button
onclick="getRanNum()">生成</button>
<body>
<script>
var
result
=
[]
function
getRanNum(){
result
=
[]
for(var
i=0i<4i++){
var
ranNum
=
Math.ceil(Math.random()
*
25)
//生成一个0到25的数字
//大写字母'A'的ASCII是65,A~Z的ASCII码就是65
+
0~25然后调用String.fromCharCode()传入ASCII值返回相应的字符并push进数组里
result.push(String.fromCharCode(65+ranNum))
}
document.getElementById('result').innerText
=
result.toString()
}
</script>
</body>
</html>
<script language="javascript">function randomString(len) {
len = len || 32
var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678' /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
var maxPos = $chars.length
var pwd = ''
for (i = 0i <leni++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos))
}
return pwd
}
document.write(randomString(32))
</script>
<script type="text/javascript">get()
function get(){
var n = 'abcdefghijklmnopqrstuvwxyz'
n = n.split('')
ran = parseInt(Math.random()*n.length+1)
n1 = n.splice(ran,1)
ran = parseInt(Math.random()*n.length+1)
n2 = n.splice(ran,1)
document.write(n1 + ' ' + n2)
}
</script>