In this article, we share the specific implementation code of alphanumeric verification code for your reference, the specific content is as follows

Create a file that requires a random alphanumeric four-digit verification code, and ensure that the four-digit letters do not repeat, and let the four-digit random verification code displayed on the page.

We begin by encapsulating a function that randomly fetches four alphanumeric captchas.function fn2() {
        var str = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789'; Var str2 =' '; (use theforLoop to randomly get characters)for(var i = 0; i < 4; I++) {var n = math.round (math.random () * 61) (61 indicates the length of the string)if(str2.indexOf(str[n]) === -1) { str2 = str2 + str[n]; If the resulting character exists in STR2, the loop needs to be executed again.else{
    i--
}
returnStr2 Output the return value of STR2Copy the code

The next step is to display the generated captcha on the page.

Add an I element to the body, set a class name, and get the element, converting the captcha every time you click the box

<body>
 <i id="box"></ I ></ body> <script> ······'box')
    box.innerHTML = fn4()
    box.onclick = function () {
        box.innerHTML = fn4()
    }
 </script>
Copy the code

Finally, we can achieve a four-digit and alphabetic captcha without repeating the condition, click on the label I and display it on the page.