一、
var v_Result;
function OneClick(event) {
console.log("detail",event.detail);
//if (event.detail == 2)
// return ;
v_Result = false;
window.setTimeout(check, 300);
function check() {
if (v_Result != false) return;
console.log("单击");
}
}
function TwoClick() {
v_Result = true;
console.log("双击");
}
<input type="button" οnclick="OneClick(event)" οndblclick="TwoClick()" value="点我">
二、
var clickTimer = null;
function _click() {
if (clickTimer) {
console.log("clearTimeout", clickTimer);
window.clearTimeout(clickTimer);
clickTimer = null;
}
clickTimer = window.setTimeout(function() {
// your click process code here
console.log("你单击了我");
},
300);
console.log("setTimeout", clickTimer);
}
function _dblclick() {
console.log("dblclick");
if (clickTimer) {
console.log("=clearTimeout", clickTimer);
window.clearTimeout(clickTimer);
clickTimer = null;
}
// your click process code here
console.log("你双击了我");
}
<button οnclick="_click();" οndblclick="_dblclick();">单击或双击我</button>
另外,根据event.detail可以获知是单击还是双击,单击detail值是1,双击值是2。但是双击时,OneClick(event)会被调用两次,第一次detail值是1,第二次值是2
参考:1、http://my.oschina.net/jsan/blog/123181
2、http://smartwang.blog.51cto.com/3270660/1415400