This article shares the specific code of JavaScript to implement click-to-switch verification code and verification for your reference. The specific content is as follows Effect: Code: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> div { width: 100px; height: 40px; background-color: red; color: #fff; text-align: center; line-height: 40px; font-size: 30px; font-weight: 900; user-select: none; } .show { position: absolute; left: 0; top: 0; right: 0; bottom: 0; margin: auto; width: 200px; height: 100px; background-color: pink; text-align: center; line-height: 100px; font-size: 40px; font-weight: 900; display: none; } </style> </head> <body> <div></div> <input type="text" value="Please enter the verification code above" /> <button>Register</button> <div class="show">Waiting. . . . </div> <script type="text/javascript"> //1000-9999 var div = document.getElementsByTagName("div"); var inp = document.getElementsByTagName("input")[0]; var btn = document.getElementsByTagName("button")[0]; div[0].innerHTML = ranFun(1000, 9999); inp.onclick = function () { this.value = "" } div[0].onclick = function () { this.innerHTML = ranFun(1000, 9999) } btn.onclick = function () { if (inp.value == div[0].innerHTML) { div[1].style.display = "block"; setTimeout(function () { location.href = "register.html" }, 3000) } else { alert('Verification code error') div[0].innerHTML = ranFun(1000, 9999); inp.value = "" } } function ranFun(a, b) { return Math.floor(Math.random() * (b - a + 1) + a) } </script> </body> </html> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: JavaScript canvas to achieve raindrop effects
>>: Native JavaScript message board
MySQL variables include system variables and syst...
Most of this article refers to other tutorials on...
Today, this post lists some great examples of circ...
1. Embed is illegal The <embed> tag is a pri...
Table of contents Preface text parameter example ...
If you want to transfer files between Windows and...
Demand background The project is made using Vue, ...
getElementById cannot get the object There is a s...
Execute Command docker run -d --name consul -p 85...
This article uses an example to illustrate the co...
Table of contents Common payment methods in proje...
Composition API implements logic reuse steps: Ext...
Table of contents 1. Create a sql script file con...
Questions about select elements in HTML have been...
Let’s not start with the introduction and get str...