<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
input[type=‘button‘]{
margin-left: 100px;
}
input{
margin-top: 200px;
}
</style>
<body>
<input type="button" id="btn" value="点击生成随机数">
<input type="text" disabled id=‘txt‘>
<script>
var btn = document.getElementById(‘btn‘);
var txt = document.getElementById(‘txt‘);
btn.onclick = function () {
txt.value = fn();
}
function fn() {
var rs = ‘‘;
var sjs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ‘f‘, ‘g‘, ‘h‘, ‘i‘, ‘j‘, ‘k‘, ‘l‘, ‘m‘, ‘n‘, ‘o‘, ‘p‘, ‘q‘,‘r‘,‘s‘,‘t‘,‘u‘,‘v‘,‘w‘,‘x‘,‘y‘,‘z‘];
//如果像生成多位数验证码,只需改变下面的4为你需要的位数值即可
for (var i = 0; i < 4; i++) {
var n = Math.floor(Math.random() * sjs.length);
var n = sjs[n];
rs = rs + n;
}
return rs;
}
txt.value = fn();
</script>
</body>
</html>