A simple example of JavaScript implementing digital verification code

Source: Internet
Author: User

  This article is mainly on the JavaScript implementation of a simple example of digital verification code, the need for friends can come to the reference, I hope to help you.

Examples are as follows: The code is as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns=" http://www.w3.org/1999/xhtml "> <head> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/>     <TITLE>JS Verification Code </title>       <style type=" Text/css ">          . Code            {         &NBS P     Background-image:url (code.jpg);                font-family:arial;                font-style:italic;                color:red;                border:0;                padding:2px 3px;                letter-spacing:3px;      &nbsP         Font-weight:bolder;            {          . Unchanged            {               border:0;            }        </style>     <script language= "javascript" type= "Text/javascript" >          var code; In global definition verification code         function createcode ()         {           code = "";           var codelength = 4;//Verification Code length           var Checkcode = document.getElementById ("Checkcode");           var Selectchar = new Array (0,1,2,3,4,5,6,7,8,9);//All candidate components of the verification code, of course, can also be used in Chinese              for (var i=0;i<codelength;i++)           {                        var CharIndex = M Ath.floor (Math.random () *10);           code +=selectchar[charindex];                       &NBSP,   //    &N Bsp Alert (code);           if (checkcode)           {            checkcode.classname= "code";             checkcode.value = code;          &nbsp,          &nbsp,          &NBS P function validate ()         {          var Inputcode = document.g Etelementbyid ("INPUT1"). Value;           if (inputcode.length <=0)           { &NBSp            alert ("Please enter the verification code!") ");          &nbsp,           else if (inputcode!= code)           {             alert ("Validation code input Error!") ");              Createcode ()/Refresh Verification Code             &nbsp ;        else           {            a Lert ("OK");          &nbsp,             }        &NBS P </script>   </head>   <body onload= "Createcode ()" >   <form  action= "#" > & nbsp      <input  type= "text"   id= "input1"/>       <input type= "text" Onclic K= "Createcode ()" readonly= "readonly" id= "Checkcode" class= "unchanged" style= "width:80px" /><br/>       <input id= "Button1"  onclick= "Validate" (); "type=" button "value=" OK "/>     </form>   </body>   </html>    

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.