js 生成验证码

<!DOCTYPE html>[color=olive][/color]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>找回密码</title>
<link type="text/css" rel="stylesheet" href="style.css" />
<style type="text/css">
.code{
font-family: Arial;
font-style: italic;
color:Red;
border:0;
padding:2px 3px;
letter-spacing: 3px;
font-weight: bolder;
width: 50px;
line-height:30px;
}
.unchanged{
border:0;
}
</style>
<script type="text/javascript" charset="utf-8">

function createCode(){
var randomCode ="";
var codeLength = 4;
var selectRange = new Array(0,1,2,3,4,5,6,7,8,9,'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');
var random = document.getElementById("random");
for(var i=0;i<codeLength;i++){
var randomIndex = Math.floor(Math.random()*34);
randomCode += selectRange[randomIndex];
}
alert(randomCode);
if(random){
random.className="code";
random.value=randomCode;
}
}
</script>
<body onload="createCode();">
   <input id="random" type="text" class="unchanged" value="" readonly="readonly"/><a href="#"onclick="createCode();"看不清,换一张</a>
</body>

你可能感兴趣的:(验证码)