Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法在超时时删除javascript中的所有函数?_Javascript_Html_Timeout - Fatal编程技术网

有没有办法在超时时删除javascript中的所有函数?

有没有办法在超时时删除javascript中的所有函数?,javascript,html,timeout,Javascript,Html,Timeout,我创建了一个拖放游戏。时间到了,有没有办法阻止所有的鼠标事件 下面是我的计时器代码 var canvas = document.getElementById("canvas"); var canvas_context = canvas.getContext("2d"); var text = "you have: 10 : 00 left" function showFillText() { canvas_context.clearRect(500, 350, 80, 100); canvas

我创建了一个拖放游戏。时间到了,有没有办法阻止所有的鼠标事件

下面是我的计时器代码

var canvas = document.getElementById("canvas");
var canvas_context = canvas.getContext("2d");
var text = "you have: 10 : 00 left"

function showFillText() {
canvas_context.clearRect(500, 350, 80, 100);
canvas_context.fillStyle = '#36F'; //text color
canvas_context.font = ' bold 20px sans-serif';
canvas_context.textBaseline = 'bottom'; 
canvas_context.fillText(text, 500, 450); //('text', x, y)
}
var mins = .1;  //Set the number of minutes you need
var secs = mins * 60;
var currentSeconds = 0;
var currentMinutes = 0;
setTimeout('Decrement()',1000);

function Decrement() {
    currentMinutes = Math.floor(secs / 60);
    currentSeconds = secs % 60;
    if(currentSeconds <= 9) currentSeconds = "0" + currentSeconds;
    secs--;
   text = currentMinutes + ":" + currentSeconds; //Set the element id you need the time put into.
    if(secs !== -1) setTimeout('Decrement()',1000);
    //document.getElementById("timerText").innerHTML = currentMinutes + ":" + currentSeconds; 
    if (currentMinutes == 0 && currentSeconds ==0)  {
    text = "TIMES UP"   
    //document.location.href = "http://www.google.com";
    }
    showFillText()
}
var canvas=document.getElementById(“canvas”);
var canvas_context=canvas.getContext(“2d”);
var text=“您还有:10:00”
函数showFillText(){
canvas_context.clearRect(50035080100);
canvas_context.fillStyle='#36F';//文本颜色
canvas_context.font='bold 20px sans serif';
canvas_context.textBaseline='bottom';
canvas_context.fillText(text,500450);/('text',x,y)
}
var mins=.1//设置所需的分钟数
var secs=分钟*60;
var currentSeconds=0;
var currentMinutes=0;
setTimeout('Decrement()',1000);
函数减量(){
当前分钟数=数学楼层(秒/60);
当前秒数=秒数%60;

if(currentSeconds保留所有事件处理程序的列表,并在计时器过期时删除它们

因此,不是:

document.getElementById("some element").addEventListener("onX", function () {});
你可以:

registerEvent(document.getElementById("some element"), "onX", function () {});

registerEvent
保留所有事件侦听器的列表。您可以使用
removeEventListener
删除事件侦听器。可以使用指针事件。对您感兴趣的div或类使用它。

添加一个名为(例如)“lock”的标志,最初设置为0

时间到后,将其设置为1

在函数中添加if

function myFunction(){
    if( lock == 0 ){
        ... function ...
    }
}

可能有一种更复杂的方法可以做到这一点,但应该可以做到…

你可以更具体一些。你实际上不想禁用所有鼠标事件,或者你的站点将停止工作。仅供参考,最好将函数引用传递给
setTimeout
,而不是字符串:
setTimeout(减量,1000);
请同时显示您的事件绑定。