首页 > 代码库 > 避免页面按钮重复提交

避免页面按钮重复提交

 1         function preventAjax(obj,num){
 2             obj.disabled = true;
 3             var num = num;
 4             var types =obj.type;
 5             if(types == ‘submit‘){
 6                 var text = obj.value;
 7                 var time1 = setInterval(function(){
 8                     obj.value =http://www.mamicode.com/ num;
 9                     num--;
10                     if(obj.value <= 0 ){
11                         clearInterval(time1);
12                         obj.disabled = false;
13                         obj.value =http://www.mamicode.com/ text;
14                     }
15                 },1000);
16             }else{
17                 var text = obj.innerHTML
18                 var time1 = setInterval(function(){
19                     obj.innerHTML = num;
20                     num--;
21                     if(obj.innerHTML <= 0 ){
22                         clearInterval(time1);
23                         obj.disabled = false;
24                         obj.innerHTML = text;
25                     }
26                 },1000);
27             }
28         }
View Code

绑定事件即可调用: