JavaScript之随机码的生成与校验
由于获取事件源有两种写法,所以在此处都附上:
这个是直接用var去定义的
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>随机验证码校验</title>
<style type="text/css">
#code{
width: 100px;
height: 100px;
background-color: #ddd;
padding: 10px;
line-height: 100px;
text-align: center;
font-size: 20px;
color: red;
/*font-weight: bold;*/
}
</style>
</head>
<body>
<div id="code"></div>
<input type="text" name="" id="newCode">
<input type="button" name="" id="validate" value="验证">
<script type="text/javascript">
window.onload = function (){
var code;
// 1.获取对应的标签
var codeDiv = document.