简单的获取验证码
<!DOCTYPE html>
<html>
<head>
<meta charset=”UTF-8″>
<title></title>
</head>
<body>
<input type=”text” name=”” id=”enter” value=”” placeholder=”请输入验证码”/><br />
<input type=”button” name=”” id=”get” value=”获取验证码” onclick=”creatCode()” />
<input type=”button” name=”” id=”check” value=”校验验证码”onclick=”checkCode()” />
<script type=”text/javascript”>
//获取验证码
var code;
function creatCode(){
code=””;
//验证码的长度
var codelength=4;
var get=document.getElementById(“get”);
var arr = new Array(0,1,\’z\’,3,\’o\’,5,6,\’j\’,\’v\’,9,\’s\’,\’d\’,\’g\’,\’m\’);
for(var i=0;i<codelength;i++){
var index = Math.floor(Math.random()*10);
code+=arr[index];
}
get.value=code;
}
//校验验证码
function checkCode(){
var enter = document.getElementById(\’enter\’).value;
if(enter!=get.value){
alert(“验证码错误”);
creatCode()
}else{
alert(“验证码正确”);
}
}
</script>
</body>
</html>