<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="button" value="点击">
<div></div>
<script>
var str = 'qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM1234567890';
var o_but = document.querySelector('input');
var o_box = document.querySelector('div');
o_but.onclick = function () {
var num = '';
for (var i = 0; i < 4; i++) { //四位验证码
//charAt 根据下标查找字符
num += str.charAt(Math.floor(Math.random() * str.length));
}
return o_box.innerHTML = num;
}
</script>
</body>
</html>
实现简易验证码
最新推荐文章于 2024-09-04 20:18:34 发布