Required effect: After clicking to send the verification code, the button is disabled and undisabled after 5 seconds. Disable button after clicking send Unban after 5 seconds and resend The code is as follows: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <input type="text"> <input type="button" value="Send"> <script src="js/jquery-1.12.4.min.js"></script> <script> // Get the element var $btn = $("input:button") // Add button click event $btn.click(function () { // Define a variable to store the time number var n = 5; // Make the button disabled // Replace the text content of the button $(this).prop("disabled",true).val(n + "s and then send again") //Change the countdown content every 1s//Use the timer to reduce the time every 1svar timer = setInterval(() => { n--; // The text content changes // The default value of this inside the timer is window $(this).val(n + "s after resending") // If the time reaches 0, stop the timer if (n <= 0) { clearInterval(timer) // After 5 seconds, you need to resume sending the text // Undisable the button $(this).val("Resend").prop("disabled",false) } },1000) }) </script> </body> </html> This is the end of this article about how to disable the send verification code control button using jQuery. For more information about disabling the jQuery control button, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Docker installation tomcat dubbo-admin instance skills
>>: Detailed explanation of how to use join to optimize SQL in MySQL
React Native can develop iOS and Android native a...
This article shares the installation and configur...
Table of contents Why use setState Usage of setSt...
1. Create a new user: 1. Execute SQL statement to...
Color contrast and harmony In contrasting conditi...
A few days ago, when I was working on a requireme...
Table of contents Why update the auto-increment i...
Zabbix deployment documentation After zabbix is ...
Table of contents 1. Check whether the docker env...
We use the translate parameter to achieve movemen...
Project Background Recently, there is a project w...
Table of contents Preface Promise chaining MDN Er...
Table of contents Overview 1. Parent component pa...
Table of contents 1. Use closures 2. Use ES6 clas...
Table of contents Method 1 Method 2 After install...