


How jQuery prevents the same event from being triggered repeatedly quickly
Jun 07, 2018 am 11:01 AMNow I will share with you a jQuery method to prevent the same event from being triggered quickly and repeatedly. It has a very good reference value and I hope it will be helpful to everyone.
Repeated triggering is to prevent users from repeatedly clicking to submit data. We usually click again if there is no response after clicking. This must not only be done from the user experience point of view, but also needs to be done in js or php program scripts. Okay, let the user know that the click is submitted and the server is processing it. Now I will sort out the script to deal with this repeated triggering problem.
Many times events will be triggered repeatedly quickly, such as click, which will execute the code twice, causing many consequences. There are many solutions now, but almost all have limitations. For example, in an Ajax form, if the user is prevented from clicking multiple times at once, the submit button can be frozen when the user clicks it for the first time, and then released when another click is allowed. Many people do this, but it doesn't work very well in other situations.
The following is a good method recommended. First, throw a function into it.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Usage method
1 2 3 4 5 |
|
The above code can wait for 300 milliseconds after clicking. If it is within 300 milliseconds If this event occurs again, the last click will be cancelled, and the timer will be restarted. Repeat this process until it has waited for 300 milliseconds before responding to the event.
This function is very useful, such as verifying input or pulling the avatar in real time based on the entered email address without having to wait until it is out of focus before pulling it.
Example
Button BUTTON class
a Label class
For the first type of situation, the button has an attribute that is disabled to control whether it can be clicked. See the code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Using vue2.0.js to implement multi-level linkage selectors
Using mint-ui to implement provinces and cities Three-level linkage effect
Using vue to implement secondary route setting method
The above is the detailed content of How jQuery prevents the same event from being triggered repeatedly quickly. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Detailed explanation of jQuery reference methods: Quick start guide

How to use PUT request method in jQuery?

How to remove the height attribute of an element with jQuery?

jQuery Tips: Quickly modify the text of all a tags on the page

Use jQuery to modify the text content of all a tags

In-depth analysis: jQuery's advantages and disadvantages

Understand the role and application scenarios of eq in jQuery

How to tell if a jQuery element has a specific attribute?
