jQuery implements the function of disabling the control button of sending verification code

jQuery implements the function of disabling the control button of sending verification code

Required effect: After clicking to send the verification code, the button is disabled and undisabled after 5 seconds.
The effect diagram is as follows:

insert image description here

Disable button after clicking send

insert image description here

Unban after 5 seconds and resend

insert image description here

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:
  • jQuery countdown resend SMS verification code function example
  • jQuery implements sending verification code and 60-second countdown function
  • Implement the countdown function after sending SMS verification code based on jQuery (ignoring page closing)
  • jQuery implements the countdown effect code sharing of sending verification code by mobile phone
  • jQuery implements the countdown code for sending verification code by mobile phone

<<:  Docker installation tomcat dubbo-admin instance skills

>>:  Detailed explanation of how to use join to optimize SQL in MySQL

Recommend

About React Native unable to link to the simulator

React Native can develop iOS and Android native a...

Detailed explanation of React setState data update mechanism

Table of contents Why use setState Usage of setSt...

MySql sets the specified user database view query permissions

1. Create a new user: 1. Execute SQL statement to...

Sharing of web color contrast and harmony techniques

Color contrast and harmony In contrasting conditi...

One sql statement completes MySQL deduplication and keeps one

A few days ago, when I was working on a requireme...

Problems encountered when updating the auto-increment primary key id in Mysql

Table of contents Why update the auto-increment i...

How to monitor mysql using zabbix

Zabbix deployment documentation After zabbix is ​...

Detailed steps for installing MinIO on Docker

Table of contents 1. Check whether the docker env...

Example of implementing translation effect (transfrom: translate) with CSS3

We use the translate parameter to achieve movemen...

Implementation of Webpack3+React16 code splitting

Project Background Recently, there is a project w...

JS asynchronous code unit testing magic Promise

Table of contents Preface Promise chaining MDN Er...

Detailed explanation of how Vue components transfer values ​​to each other

Table of contents Overview 1. Parent component pa...

Creating private members in JavaScript

Table of contents 1. Use closures 2. Use ES6 clas...

Solution to PHP not being able to be parsed after nginx installation is complete

Table of contents Method 1 Method 2 After install...