MainActivity

代码

 

第一种方法

var forbidRepeartClick = (function(){
	var instance = null;
	var canClick = true;
	function Build(){
		this.setClick = function(callback){
			if(canClick){
				canClick = false;
				callback()
				setTimeout(function(){
					canClick = true;
				},2000)
			}else{
				console.log(\'两秒之内限制重复点击\')
			}
		}
	}
	
	
	if(!instance){
		instance = new Build();
		console.log(\'创建实例\')
	}
	
	return instance;
})()

  

使用

$("#box").click(function(){
			forbidRepeartClick.setClick(function(){
				// 将点击执行的代码放在这里就可以实现 防止重复执行
				
			})
		})

  

 

 

第二种方法

function C(callback){
	C.prototype.init(callback);
}
C.prototype = {
	canclick: true,
	init: function(callback){
		if(this.canclick){
			this.canclick = false
			callback();
			setTimeout(function(){
				this.canclick = true
			}.bind(this),2000)
		}else{
			console.log(\'两秒未到不允许点击\')
		}
	}
}

  

使用

$("#box").click(function(){
			C(function(){
				// 将点击执行的代码放在这里就可以实现 防止重复执行
			});
		})

  

 

分类:

技术点:

相关文章:

  • 2021-11-17
  • 2021-11-12
  • 2021-10-26
  • 2021-11-15
  • 2021-11-03
  • 2021-11-17
  • 2021-11-03
  • 2021-05-23
猜你喜欢
  • 2021-11-03
  • 2021-11-03
  • 2021-11-03
  • 2021-08-29
  • 2021-11-03
  • 2021-11-03
  • 2021-10-12
相关资源
相似解决方案