Get a four-digit random verification code (including numbers and letters)

Source: Internet
Author: User

<! 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.