<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> Random Verification Code </title>
<style>
body{padding:50px;}
#vcode {padding:10px;border:1px solid #ddd; background: #efefef; font-size:30px;}
</style>
<script>
Window.onload = function () {
/*
1) Get elements
2) give #btnrandom a fixed-point hit event
* Randomly generate a 4 for verification code
* Write verification code to #vcode
*/
1) Get elements
var vcode = document.getElementById (' Vcode ');
var btnrandom = document.getElementById (' btnrandom ');
var str = ' abcdefghijklmnopqrstuvwxyz0123456789 ';//str[35]
Btnrandom.onclick = function () {
Randomcode ();
}
Randomcode ();
Encapsulation functions
function Randomcode () {
Randomly generate a 4-digit verification Code (with letters)
var _code = ';
for (Var i=0;i<4;i++) {
var index = parseint (Math.random () *str.length)//cannot be greater than 36
_code + = Str[index]
}
vcode.innerhtml = _code.touppercase ();
}
}
</script>
<body>
<span id= "Vcode" >1998</span>
<button id= "Btnrandom" > re-acquisition </button>
</body>
Get a four-digit random verification code (including numbers and letters)