随机生成不区分大小写的验证码


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<style type="text/css">
body{text-align: center;}
.code
{
font-family: Arial;
font-style: italic;
color: red;
border: 0;
padding: 2px 10px;
letter-spacing: 2px;
font-weight: bolder;
}

</style>
<body>


<input type="text" id="input1" />
<input type="text" onclick="createCode()" id="checkCode" style="width: 45px;background: #660099"/>


<script type="text/javascript" src="https://qunarzz.com/jquery/prd/jquery-1.7.2.js"></script>
<script language="javascript" type="text/javascript">

var code;

function createCode() {
code = "";
var checkCode = document.getElementById("checkCode");


function RndNum(num) {
var str = '0123456789qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM';
var str1 = '';
for (var i=0;i < num;i++){

str1 +=str[Math.floor(Math.random()*str.length)];
}

return str1;
}

var num = RndNum(4);

code = num;
if (checkCode) {
checkCode.className = "code";
checkCode.value = code;
}

}
</script>
<script type="text/javascript">
$(document).ready(function () {
createCode();
$("#input1").blur(function () {
var inputCode = document.getElementById("input1").value;
if (inputCode.length <= 0) {
alert("请输入验证码!");
}
else if (inputCode != code.toLowerCase()) {
alert("验证码输入错误!");
createCode(); //刷新验证码
}
else {
alert("OK!,璐璐蠢!");
}
});
})
</script>
</body>
</html>

posted @ 2017-03-22 17:57  天--安静  阅读(1858)  评论(0编辑  收藏  举报