首页  >  文章  >  web前端  >  javascript实现避免页面按钮重复提交_javascript技巧

javascript实现避免页面按钮重复提交_javascript技巧

WBOY
WBOY原创
2016-05-16 16:21:351504浏览

复制代码 代码如下:

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                         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                         clearInterval(time1);
                        obj.disabled = false;
                        obj.innerHTML = text;
                    }
                },1000);
            }
        }

绑定事件即可调用

以上就是本文的全部内容了,小伙伴们拿到自己项目中测试下吧。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn