<HTML> <Metacharset="UTF-8"> <title>js Generate verification Code </title> <styletype="Text/css">.Code{/* Background-image:url (code.jpg) *//* here with a local picture on the OK * *Background-color:Aquamarine;font-family:Arial;Font-style:Italic;Color:Red;Border: 0;padding: 2px3px;letter-spacing: 3px;Font-weight:Bolder; }
.unchanged{Border: 0; } </style> <Scriptlanguage="JavaScript"type="Text/javascript">varCode; To define a validation code globallyfunctionCreatecode () {Code="";varCodelength = length of 6;//verification codevarCheckcode =Document. getElementById ("Checkcode");varSelectchar =NewArray (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 ',' A ',' B ',' C ',' d ',' E ',' F ',' G ',' h ',' I ',' J ',' K ',' l ',' m ',' n ',' O ',' P ',' Q ',' W ',' x ',' y ',' Z '//All candidate components of the verification code, of course, can also be used in Chinese for(vari = 0; i < codelength; i++) {varCharIndex =Math. Floor (Math. Random () * (36+26));Code+ + Selectchar[charindex]; }//alert (code);if(Checkcode) {Checkcode.ClassName="Code"; Checkcode.value=Code; }
}functionValidate () {varInputcode =Document. getElementById ("INPUT1").value;if(Inputcode.length<= 0) {alert ("Please enter a verification code." "); }else if(Inputcode!=Code) {alert ("Validation code input error. "); Createcode ()//Refresh authentication Code}Else{Alert ("^-^ OK"); }} </Script> </ Head> < Bodyonload="Createcode ()"> <formaction="#"> <inputtype="Text"id="INPUT1"/> <inputtype="Text"onclick="Createcode ()" readonly="ReadOnly"id="Checkcode"class="Unchanged"style="width: 80px" /><BR/> <inputid="Button1"onclick="Validate ();" type="button"value="OK"/> </form> </ Body> </HTML>
<HTML> <Metacharset="UTF-8"> <title>js Generate verification Code </title> <styletype="Text/css">.Code{/* Background-image:url (code.jpg) *//* here with a local picture on the OK * *Background-color:Aquamarine;font-family:Arial;Font-style:Italic;Color:Red;Border: 0;padding: 2px3px;letter-spacing: 3px;Font-weight:Bolder; }
.unchanged{Border: 0; } </style> <Scriptlanguage="JavaScript"type="Text/javascript">varCode; To define a validation code globallyfunctionCreatecode () {Code="";varCodelength = length of 6;//verification codevarCheckcode =Document. getElementById ("Checkcode");varSelectchar =NewArray (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 ',' A ',' B ',' C ',' d ',' E ',' F ',' G ',' h ',' I ',' J ',' K ',' l ',' m ',' n ',' O ',' P ',' Q ',' W ',' x ',' y ',' Z '//All candidate components of the verification code, of course, can also be used in Chinese for(vari = 0; i < codelength; i++) {varCharIndex =Math. Floor (Math. Random () * (36+26));Code+ + Selectchar[charindex]; }//alert (code);if(Checkcode) {Checkcode.ClassName="Code"; Checkcode.value=Code; }
}functionValidate () {varInputcode =Document. getElementById ("INPUT1").value;if(Inputcode.length<= 0) {alert ("Please enter a verification code." "); }else if(Inputcode!=Code) {alert ("Validation code input error. "); Createcode ()//Refresh authentication Code}Else{Alert ("^-^ OK"); }} </Script> </ Head> < Bodyonload="Createcode ()"> <formaction="#"> <inputtype="Text"id="INPUT1"/> <inputtype="Text"onclick="Createcode ()" readonly="ReadOnly"id="Checkcode"class="Unchanged"style="width: 80px" /><BR/> <inputid="Button1"onclick="Validate ();" type="button"value="OK"/> </form>