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 = num; 9 num--;10 if(obj.value <= 0 ){11 clearInterval(time1);12 obj.disabled = false;13 obj.value = text;14 }15 },1000);16 }else{17 var text = obj.innerHTML18 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 }
绑定事件即可调用: