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;  ,  , &NBS P function validate () { var Inputcode = document.g Etelementbyid ("INPUT1"). Value; if (inputcode.length <=0) {&NBSP;&NBSp alert ("Please enter the verification code!") ");  , else if (inputcode!= code) { alert ("Validation code input Error!") "); Createcode ()/Refresh Verification Code   ; else { a Lert ("OK");  , } &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>