js防止短时间内重复点击

//重复点击限制
    function fn(callback) {
        fn.prototype.init(callback);
    }

    fn.prototype = {
        canclick: true,
        init: function (callback) {
            if (this.canclick) {
                this.canclick = false;
                callback();
                setTimeout(function () {
                    this.canclick = true
                }.bind(this), 1000)
            }
        }
    };
、、、、、、、、、、、、、、、、
//调用
function xx(){
   fn(function(){
      // 要执行的代码
   }); 
  
}    

 

posted @ 2020-10-28 11:11  pengcx  阅读(397)  评论(0编辑  收藏  举报