4-digit random verification code generation

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>4位随机验证码的生成</title>
<style>
label{
color:aqua;
float:left;
font-size: 20px;
line-height:2em;
}
#tex{
display:inline-block;
width:50px;
height: 25px;
float:left;
text-align: center;
font-size:15px;
margin-top:10px;
}
#showyz{
border:3px solid green;
color:blue;
width:90px;
height:40px;
text-align:center;
float:left;
margin-left:15px;
line-height: 2.5em; }


#hyz{
background-color:burlywood;
border:1px solid burlywood;
width:50px;
height:20px;
float: left;
margin-left:20px;
margin-top: 10px;
margin-right:15px;
}
#btn{ } </style> </head> <body> <label for="tex">请输入验证码:</label><input type="text" id="tex" maxlength="4" autofocus> <div id="showyz"></div> <div id="hyz">换一张</div><br> <input type="button" id="btn" value="确认"> </body> <script> codes.push(i); for(var i=48;i<=57;i++ ){ //Save the codes corresponding to numbers in the codes array, the range of digital codes is [48-57] var codes=[]; //Define an empty array to save 62 codes
















}
//Save the code corresponding to the uppercase letter to the codes array, the corresponding code range [65-90]
for(var i=65;i<=90;i++){
codes.push(i);
}
//The lowercase letter The code corresponding to the letter is stored in the codes array, corresponding to the code range [97-122]
for(var i=97;i<=122;i++){
codes.push(i);
}
//Define a method to generate 62-bit random The number returns a random code as an array index, and then converts its code to the corresponding number or letter
function suiji(){
var arr=[];//Define an array to save 4 random numbers
for(var i=0;i< 4;i++){
var index=Math.floor(Math.random()*(61-0+1)+0);//Generate a random number
var char=String.fromCharCode(codes[index]);// Decode
arr.push(char); //Store in the array arr
}
return arr.join("");//Convert the array to a string, separated by spaces, and return
}
var yzm=suiji();/ /Call the method to return the put back verification code to yzm
//Get the above elements
Verification code input errors, please re-enter! ");





















yzm=suiji();
   showyz.innerHTML=yzm;
tex.value="";
}
}
</script>

</html>






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324738548&siteId=291194637