效果图
![image-20210311225505026](https://gitee.com/wx_3d25ad0b9a/img/raw/master/img/image-20210311225505026.png)
随机验证码
<!DOCTYPE html>
<html>
<head>
<title>随机验证码</title>
</head>
<body>
<script type="text/javascript">
//获取最大到最小之间的数
function random(min,max){
return Math.floor(Math.random()*(max-1)+ min);
}
//随机验证码 四位 数字+字母(大写)
function creatCode(){
//设置默认的空的字符串
var code = '';
//设置长度
var codeLength =4;
var allcode = [0,1,2,3,4,5,6,7,8,9,'q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m'];
for(var i = 0;i<codeLength;i++){
//设计随机范围 0~36
var index = random(0,36);
code += allcode[index];
}
return code;
}
var rndcode = creatCode();
console.log(rndcode);
document.write(`<h1>${rndcode}</h1>`);
</script>
<form>
<input type="submit" value="刷新">
</form>
</body>
</html>