4位验证码验证(练习)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="text" id="a">
<input type="submit" id="b" value="登录">
<div id="c"></div>

<script>
var a=document.getElementById("a");
var b=document.getElementById("b");
var c=document.getElementById("c");
var n=parseInt(Math.random()*9000)+1000;
c.innerHTML=n;

b.onclick=function()
{
if(a.value=="")
alert("null");
else
{if(a.value==n)
alert("ok");
else
alert("err");
}
}
</script>
</body>
</html>

posted @ 2017-04-19 23:06  非凡。  阅读(2037)  评论(0编辑  收藏  举报