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
This article will introduce an interesting pseudo...
As an open source software, Apache is one of the ...
Preface I recently sorted out my previous notes o...
What you learn from books is always shallow, and ...
This article example shares the specific code for...
BMP is an image file format that is independent o...
Preface As a DBA, you will often encounter some M...
1. Navigation: Unordered List vs. Other Label Ele...
Samba Services: This content is for reference of ...
After reading the following article, you can depl...
Table of contents 1. Introduction 2. About vue-si...
When using Docker in a production environment, da...
1. Check the database time zone show variables li...
Linux often encounters situations such as adding ...
Install mysql5.7.21 in the window environment. Th...