How to generate CAPTCHA randomly by JS
This article is about how JS can generate CAPTCHA randomly. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The details are as follows
111111 can't see another CAPTCHA: make sure var arr = ["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", "r", "s", "t", "u", "v", "w", "x", "y", "z", 0r 1, 3, 4, 6, 7, 8] Var h2=document.querySelector ("H2"); var btn=document.querySelector ("button"); var change=document.querySelector ("a"); var input=document.querySelector ("input"); function fn () {var arr1=Math.floor (Math.random () * 62); var arr2=Math.floor (Math.random () * 62); var arr3=Math.floor (Math.random () * 62) Var arr4=Math.floor (Math.random () * 62); var arr5=Math.floor (Math.random () * 62); var arr6=Math.floor (Math.random () * 62); var yz= "+ arr [arr1] + arr [arr2] + arr [arr3] + arr [arr4] + arr [arr5] + arr [arr6]; H2 [XSS _ clean] = yz; btn.onclick=function () {alert (input.value) If (input.value==yz) {alert (correct);} else {alert (error);} fn (); change.addEventListener ("click", fn)
1. Math.floor () method
Math.floor (x)
The floor () method returns the largest integer less than or equal to x.
If the parameter passed is an integer, the value remains the same.
2. Math.random () method
The random () method returns a random number between 0 (inclusive) and 1 (not inclusive).
The function of taking random numbers can be realized by using the above two methods.
Thank you for reading! This is the end of the article on "how to randomly generate CAPTCHA in JS". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!