【原创】jQuery单击事件和双击事件相互不影响实现

使用方法 第一个参数 单击事件处理,第二个参数 双击事件处理

$("#mm").onClick(function(e){
  console.debug("单击事件.");
 },function(e){
  console.debug("双击事件.");
 });

jQuery组件实现代码

//鼠标单击和双击事件组件
$.fn.onClick = function(onClick, onDblclick){ 
    return this.each(function(){
    	var timer = null;
        var target = this; 
        $(this).click(function(e){ 
            clearTimeout(timer); 
            timer = setTimeout(function(){
            	(onClick || $.noop).call(target, e);
            }, 400); 
        }).dblclick(function(e) { 
            clearTimeout(timer); 
            (onDblclick || $.noop).call(target, e); 
        });
    }); 
};

猜你喜欢

转载自blog.csdn.net/wellse/article/details/84483899
今日推荐