var timer = null;
//单击
function do_click(event,callBack) {
clearTimeout(timer); // 这里加一句是为了兼容 Gecko 的浏览器 /
if (event.detail == 2)
return ;
timer = setTimeout(function() {
typeof(callBack) === 'function' && callBack.call();
}, 300); };
//双击
function do_dblclick(event,callBack) {
clearTimeout(timer);
typeof(callBack) === 'function' && callBack.call();
};
$('#test').click(function(e){
do_click(e,function(){console.log('click')});
});
$('#test').dblclick(function(e){
do_dblclick(e,function(){console.log('dblclick')});
});
参考链接