<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>随机验证码</title>
</head>
<body>
<p>验证码:</p>
<div id="login" onclick="change()"></div>
</body>
<script>
function getCode(n) {
// var all = "azxcvbnmsdfghjklqwertyuiopZXCVBNMASDFGHJKLQWERTYUIOP0123456789";
// var all = "ZXCVBNMASDFGHJKLQWERTYUIOP0123456789";
var all = "0123456789";
var b = "";
for (var i = 0; i < n; i++) {
var index = Math.floor(Math.random() * 10);
b += all.charAt(index);
}
return b;
}
function change() {
document.getElementById("login").innerHTML = getCode(4);
}
window.onload = change;
</script>
</html>