Javascript implementation to avoid repeated page button submissions _ javascript tips-js tutorial

Source: Internet
Author: User
In many cases, we need to prevent repeated submissions. There are also many articles in this regard, and there are great differences in implementation methods. sometimes, even if the server can identify repeated submissions, it may cause problems. for example, if an operation that takes a long wait time is submitted repeatedly after the first submission, the page may die. this problem can be prevented by using scripts. The Code is as follows:


Function preventAjax (obj, num ){
Obj. disabled = true;
Var num = num;
Var types = obj. type;
If (types = 'submit '){
Var text = obj. value;
Var time1 = setInterval (function (){
Obj. value = num;
Num --;
If (obj. value <= 0 ){
ClearInterval (time1 );
Obj. disabled = false;
Obj. value = text;
}
},1000 );
} Else {
Var text = obj. innerHTML
Var time1 = setInterval (function (){
Obj. innerHTML = num;
Num --;
If (obj. innerHTML <= 0 ){
ClearInterval (time1 );
Obj. disabled = false;
Obj. innerHTML = text;
}
},1000 );
}
}

Bind events to call

The above is all the content in this article. Let's test it in your project.

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.