Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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 - Fatal编程技术网

Javascript 清除特定超时

Javascript 清除特定超时,javascript,Javascript,如何清除此超时: var timeout = setTimeout(function() { window.setTimeout(arguments.callee, 1000); }, 1000) clearTimeout(timeout)不工作。每次设置新超时时,都需要重新分配timeout。并去掉参数。被调用方。 尝试以下工作示例: <button onclick="myFunction()">Try it</button> <button oncli

如何清除此超时:

var timeout = setTimeout(function() {
    window.setTimeout(arguments.callee, 1000);
}, 1000)

clearTimeout(timeout)
不工作。

每次设置新超时时,都需要重新分配
timeout
。并去掉
参数。被调用方
。 尝试以下工作示例:

<button onclick="myFunction()">Try it</button>
<button onclick="myStopFunction()">Stop the alert</button>

<script>
var timeout;

function myFunction() {
    timeout = setTimeout(function timerHandler() {
        timeout = setTimeout(timerHandler, 1000);
    }, 1000)
}

function myStopFunction() {
    clearTimeout(timeout);
}
</script>
试试看
停止警报
var超时;
函数myFunction(){
timeout=setTimeout(函数timerHandler(){
超时=设置超时(timerHandler,1000);
}, 1000)
}
函数myStopFunction(){
clearTimeout(超时);
}

每次设置新超时时,都需要重新分配
超时。并去掉
参数。被调用方
。 尝试以下工作示例:

<button onclick="myFunction()">Try it</button>
<button onclick="myStopFunction()">Stop the alert</button>

<script>
var timeout;

function myFunction() {
    timeout = setTimeout(function timerHandler() {
        timeout = setTimeout(timerHandler, 1000);
    }, 1000)
}

function myStopFunction() {
    clearTimeout(timeout);
}
</script>
试试看
停止警报
var超时;
函数myFunction(){
timeout=setTimeout(函数timerHandler(){
超时=设置超时(timerHandler,1000);
}, 1000)
}
函数myStopFunction(){
clearTimeout(超时);
}

您正在将
超时设置为第一次调用
setTimeout
的结果,但没有设置任何后续调用。你可能想要

var timeout;

timeout = setTimeout(function() {
  timeout = window.setTimeout(arguments.callee, 1000);
}, 10);

clearTimeout(timeout);
但这最好写为

function iter() {
  timeout = setTimeout(iter, 1000);
}

您正在将
timeout
设置为第一次调用
setTimeout
的结果,但没有设置任何后续调用。你可能想要

var timeout;

timeout = setTimeout(function() {
  timeout = window.setTimeout(arguments.callee, 1000);
}, 10);

clearTimeout(timeout);
但这最好写为

function iter() {
  timeout = setTimeout(iter, 1000);
}

将超时存储在递归范围之外的变量中。由于IE的限制,还应避免使用arguments.callee。你可以检查一把正在工作的小提琴


将超时存储在递归范围之外的变量中。由于IE的限制,还应避免使用arguments.callee。你可以检查一把正在工作的小提琴


您是否尝试过在函数中将其更改为
timeout=setTimeout(..)
?您可能想阅读。@patrickbar为什么会有什么不同?您想实现什么?您在timeout内有timeout:)我认为您可以使它更简单。尝试添加clearTimeout(超时);log('been in this line!');您将知道您的代码是否已输入。您只是清除第一个超时,而不是内部超时,而不是使用
窗口。setTimeout
您是否尝试在函数中将其更改为
timeout=setTimeout(…)
?您可能想要读取。@patrickbar为什么会有任何不同?您想要实现什么?您在timeout内有timeout:)我认为您可以使它更简单。尝试添加clearTimeout(超时);log('been in this line!');您将知道您的代码是否已输入。您只清除第一个超时,而不是内部超时否,请避免使用
参数。被调用方
,因为这是一种不好的做法,已弃用,在严格模式下根本无法工作。这也是正确的,但它是两者的组合,避免使用
参数。被调用方
,因为这是一种不好的做法,已被弃用,并且在严格模式下根本无法工作。这也是正确的,但它是两者的组合