<!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>

版权声明:本文为weixin2623670713原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/weixin2623670713/p/12970972.html