In many apps and websites, when we log in or register an account, there will be a place to send SMS verification codes 1. However, in order to prevent malicious acquisition of verification codes, we generally set a clickable time interval. After the time interval 1 is over, it can continue to be sent. Next, use code to implement The code is as follows <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> Mobile phone number: <input type="text"><button>Send verification code</button> <script> var btn = document.querySelector('button') var time=3 btn.addEventListener('click',function () { btn.disabled=true var timer = setInterval(function () { if (time<0){ clearInterval(timer) btn.disabled=false btn.innerHTML = 'Send verification code' time=3 }else { btn.innerHTML = 'remaining' + time + 'seconds' time -= 1 } },1000) }) </script> </body> </html> The effect is as follows Code explanation <br /> Here, because we only change the style and function of the button, we only get the button and then set a time variable, which is the countdown time. Then set the click event. When we click this button, the disable of this button becomes true, which means it cannot be clicked. This is the end of this article about using Javascript to implement the interval of sending SMS verification codes. For more relevant js content about sending SMS verification codes, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: nginx configuration location summary location regular writing and rewrite rule writing
>>: Innodb system table space maintenance method
1. Add MySQL Yum repository MySQL official websit...
Suppose now you want to add an item like this to ...
MySQL 8.0 for Windows v8.0.11 official free versi...
statement : This article teaches you how to imple...
Solution Abandon the Linux virtual machine that c...
Rendering After looking up relevant information o...
Table of contents 1 Problems encountered in trans...
For the beginner's first installation of MySQ...
Effect picture: Implementation code: <template...
Solution 1 Completely uninstall and delete all da...
1. Download address: mysql-8.0.17-winx64 Download...
background As the company's sub-projects incr...
Table of contents Scenario Try to solve solve Sce...
First of all, you need to understand why you use ...
A recent business involves such a requirement tha...