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.