1<!doctype html>234<meta charset= "UTF-8" >5<title>Document</title>6<script>7 //randomly generated verification code:8 //STEP1: Put all the alternate characters in the array9 varchars=[];Ten for(vari=48; Onei<=57; AChars.push (String.fromCharCode (i)), i++); - for(varI=65; -I<=90; theChars.push (String.fromCharCode (i)), i++); - for(vari=97; -i<=122; -Chars.push (String.fromCharCode (i)), i++); + //Console.log (String (chars)); - //Step2: Define function GetCode, randomly select 4-position characters + functionGetCode () { A //I start from 1, to <=4 end, while declaring the empty string code at for(varI=1,code= ""; i<=4;i++){ - //randomly pick a location from 0~chars's length-1 and save it in R - varR=math.floor (Math.random () *(Chars.length)); - //stitching the characters of R position in chars to code -code+=Chars[r]; - } in returnCode; - } to Console.log (GetCode ()); + //Step3: Repeatedly ask the user to enter the verification code: - //declares the variable code, initialized to a verification code returned by GetCode () the varCode=GetCode (); * //repeatedly ask the user to enter the verification Code (code) into lowercase results, not equal to the result of code to lowercase letters $ while(Prompt ("Enter the verification code (" +code+ ")"). toLowerCase ()Panax Notoginseng!=code.tolowercase ()) { -Alert ("The verification code is wrong! ")//hint: wrong CAPTCHA! the //call GetCode () to get a new captcha saved in code +Code=GetCode (); A}//(traversal end) thedocument.write ("); +</script> - $<body> $ -</body> -
javascript--Analog Verification Code