<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <title>javascript Verification Code Implementation Code _ cloud-dwelling community test </ title> <style type= "Text/css" > Code {} {Background-image:url (code.jpg); font-family:arial; Font-style:italic; color:red; border:0; PADDING:2PX 3px; letter-spacing:3px; Font-weight:bolder; }. Unchanged {} {border:0; } </style> <script language= "javascript" type= "Text/javascript" > var code; The global definition Validation code function createcode () {code = ""; var codelength = 6;//The length of the authentication code var checkcode = document.getElementById ("Checkcode"); var Selectchar = new Array (0,1,2,3,4,5,6,7,8,9, ' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ', ' Q ' , ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z ');//All the characters that make up the verification code, of course, can also be in Chinese for (Var i=0;i<codelength;i++) {var charIndex = Ma Th.floor (Math.random () *36); Code +=selectchar[charindex]; } if (Checkcode) {checkcode.classname= "code"; Checkcode.value = code; The function validate () {var inputcode = document.getElementById ("INPUT1"). Value; if (Inputcode.length <=0) {alert ("Please enter the verification code!") "); else if (Inputcode!= code) {alert ("Validation code input Error!) "); Createcode ()//Refresh Verification code} else {alert ("^-^ OK"); } </script> </pead> <body onload= "Createcode ()" > <form action= "#" > <input type= "Text" Id= "input1"/> <input type= "text" onclick= "Createcode ()" readonly= "readonly" id= "Checkcode" class= "unchanged"/& Gt <input id= "Button1" onclick= Validate (); "type=" button "value=" OK "/> </form> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]