Native JS Write verification code

Source: Internet
Author: User

1. First create an input box for the user to enter a verification code and a span container to hold the system given the verification code and a refresh button and a login button

class= "DL" id= "Sryzm"  /><br/><span id= "Ysyzm" style= "Color:white  ; font-weight:bolder ; font-size:18px; min-width:70px "></span>
<input id= "Sxyzm" type= "button" class= "btn Btn-default" value= "Refresh" style= "font-weight:200"/>
<input type= "button" class= "btn Btn-default" id= "btn" value= "Login" style= "Font-weight:bolder"/>

2.JS Code

1<script type= "Text/javascript" >2 varYsyzm = "";//Original Verification Code3 varSryzm = "";//Input Verification Code4$ (document). Ready (function(e) {//Page one load complete on execution method5     6     varstr = "QGFH12KJQWFEFEW3ESAEWE544SSGW6GGGGU5MWEE6777EEWW7B67FEC";7     varn = 5, s = "";8      for(vari = 0; I < n; i++){9         var Rand= Math. Floor(Math.random () * str.length);Ten          Ones + = Str.charat (Rand); A     } -$ ("#ysyzm").HTML (s); -Ysyzm =s; the      -$ ("#sxyzm"). Click (function() {//To refresh button plus Click event -                  -S= ""; +                  -                  for(vari = 0; I < n; i++){ +                 var Rand= Math. Floor(Math.random () * str.length);//Specify selection location As + = Str.charat (Rand);//Specify selection characters at                  -                 /*the random () method can return a random number between 0 and 1.  - Math.floor A mathematical function, the floor of a floating-point number is the one nearest to it, whose value is less than or equal to the floating-point.  - The charAt (int index) method is a method that can be used to retrieve a string instance of a character under a specific index. - the CharAt () method returns a char value at the specified index position. The index range is 0~length () -1. - such as: Str.charat (0) retrieves the first character in Str, Str.charat (Str.length ()-1) retrieves the last character.*/ in                  -                 } to$ ("#ysyzm").HTML (s); +Ysyzm =s; -          the         }); *      $     Panax Notoginseng      -$ ("#btn"). Click (function() {//Add click event to login button theSryzm = $ ("#sryzm").Val (); +             //take username and password A             varA = $ ("#uid").Val (); the             varB = $ ("#pwd").Val (); +             varAA = Ysyzm.toLowerCase ();//In order to implement the input is not case-sensitive, in comparison, the original verification code and input verification code are converted to lowercase letters can be -             varbb = Sryzm.toLowerCase (); $             if(aa==BB)//Two verification code to compare, if the same time, execute the following code ${alert (123)}

Native JS Write verification code

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.