码迷,mamicode.com
首页 > 其他好文 > 详细

前台生成验证码

时间:2017-09-25 09:45:30      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:dom   select   前台   blog   http   cas   family   cli   letter   

<html>
<head>
<script language="javascript" type="text/javascript">
var code ;
function createCode(){ 
code = new Array();
var codeLength = 4;
var checkCode = document.getElementById("checkCode");
checkCode.value = "";
var selectChar = new Array(2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z);
for(var i=0;i<codeLength;i++) {
   var charIndex = Math.floor(Math.random()*32);
   code +=selectChar[charIndex];
}
checkCode.value = code;
}
function validate () {
var inputCode = document.getElementById("yzm").value.toUpperCase();
if(inputCode != code ){ alert("验证码错误!"); return false; }
else { alert("验证码正确!"); return true; }
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body onLoad="createCode();">
验证码:<input type="text" id="yzm" size="5" />
<input type="button" id="checkCode" onClick="createCode()" title="刷新验证码" style="width:50px;color:#F00;border:0;letter-spacing:1px;font-family:Arial;" />
<input type="button" id="Button1" onClick="validate();" value="确定" />
</body>
</html>

 

前台生成验证码

标签:dom   select   前台   blog   http   cas   family   cli   letter   

原文地址:http://www.cnblogs.com/vichin/p/7590266.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!