Js prevents users from submitting tools multiple times, and js prevents submission

Source: Internet
Author: User

Js prevents users from submitting tools multiple times, and js prevents submission

Download, export, and other functions are often used during web development. When a user is operating on a network delay or a large amount of data, the user may experience slow response, and the operation will be deemed ineffective. Repeated clicks may cause multiple data loading and downtime, to avoid this, You can restrict your operations. For example, an operation can be performed once in five seconds.

Here is my method: it can be made into a public method for multiple js calls.

Js and jQuery used: Imports jQuery when using it.

Function delay (obj ){

Alert ("the button turns gray after you click it. It will be restored in 5 seconds !! "); // Prompt to the user

$ (Obj). attr ("disabled", "disabled ");

SetTimeout (function () {$ (obj). attr ("disabled", "");}, 5000 );

}

Put this method in the onclick event of the Import or Download button, for example, onclick = "dowloud (), delay (this);". Remember to add this.

If you want to use id, replace obj with ("# id name. But it is not universal and can only be used in one place. You need to change the id name in another place.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.