`
源代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>验证码的实现_固定四位版</title>
<script>
function verificationCode() {
var arr = ["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",
0,1,2,3,4,5,6,7,8,9];
var rand1 = Math.floor((Math.random()*62));
var rand2 = Math.floor((Math.random()*62));
var rand3 = Math.floor((Math.random()*62));
var rand4 = Math.floor((Math.random()*62));
var rand5 = Math.floor((Math.random()*62));
var rand6 = Math.floor((Math.random()*62));
alert("验证码为: " + " " + arr[rand1] + " " + arr[rand2] + " " + arr[rand3] + " " + arr[rand4] + " " + arr[rand5] + " " + arr[rand6]) ;
//document.write("验证码为: " + arr[rand1] + arr[rand2] + arr[rand3] + arr[rand4]);
}
</script>
<style>
p{
margin: 0 auto;
}
#but{
height: 40px;
width:200px;
}
</style>
</head>
<body>
<p align="center">
<input type="button" value="单击即可产生六位随机验证码" onclick="verificationCode()" id="but">
</p>
</body>
</html>