生成验证码
主要实现在浏览器警告框中产生一串随机的验证码
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title>验证码</title>
<script>
function testCode(n){ //n位验证码
var code = [];
for(var i = 0; i < n; i++){
var num = parseInt(Math.random() * 123);
if(num >=0 && num <=9){
code.push(num);
}else if(num >= 65 && num <= 90|| num >= 97 && num <= 122){
code.push(String.fromCharCode(num));
}else{
i--;
}
}
return code.join("");
}
alert(testCode(6));
</script>
</head>
<body>
</body>
</html>