var timer;
var object;
var thing;
var digit="0";
//this function fires when a single click occurs
function one(event){
timer = setTimeout("AddDigit(object)",500);
object = event;
}
//The AddDigit function keeps firing right after my double click function
function AddDigit(x){
object=x;
if (eval(digit) == 0){ digit = object; }
else{ digit = digit + object; }
document.calculator.display.value = object;
}
// This function is supposed to stop the AddDigit function from firing...
document.ondblclick = function(button){
clearTimeout(timer);
thing=button.target;
thing.setAttribute("class","duction");
}
答案 0 :(得分:1)
双击调度两个点击事件,然后双击事件。第二次调用one
时,它会用新ID替换timer
,但原始超时仍然准备好了。当调用dblclick处理程序时,它会清除第二个超时,但不会清除第一个超时。
解决方案是在分配one
之前清除timer
中的所有现有超时。
function one(event)
{
clearTimeout(timer);
timer = setTimeout(function() {
AddDigit(event);
}, 500);
}