JavaScript setInterval 和clearInterval 不起作用
我试图在最简单的情况下使用 setInterval 和clearInterval:
var passiveInterval = "";
var activeInterval = "";
function myStartFunction()
{
...
passiveInterval = window.setInterval(passiveCheck, pIntAmt);
activeInterval = window.setInterval(activeCheck, aIntAmt);
...
}
function myEndFunction()
{
...
if (passiveInterval != "")
{
alert("passiveInterval: " + passiveInterval);
window.clearInterval(passiveItnerval);
passiveInterval = "";
}
if (activeInterval != "")
{
window.clearInterval(activeInterval);
activeInterval = "";
}
...
}
令人难以置信的是警报触发,并给我正确的间隔值(整数),但随后clearInterval语句触发:
ReferenceError:Can't查找变量:passiveItnerval
我已经尝试过对窗口的每个排列进行此操作,并将其打在所有内容的前面,但没有任何效果......
I am trying to use setInterval and clearInterval in literally the simplest case possible:
var passiveInterval = "";
var activeInterval = "";
function myStartFunction()
{
...
passiveInterval = window.setInterval(passiveCheck, pIntAmt);
activeInterval = window.setInterval(activeCheck, aIntAmt);
...
}
function myEndFunction()
{
...
if (passiveInterval != "")
{
alert("passiveInterval: " + passiveInterval);
window.clearInterval(passiveItnerval);
passiveInterval = "";
}
if (activeInterval != "")
{
window.clearInterval(activeInterval);
activeInterval = "";
}
...
}
The incredible thing is that the alert triggers, and gives me the correct value of the interval (an integer), but then the clearInterval statement triggers:
ReferenceError: Can't find variable: passiveItnerval
I have tried this with every permutation of window and this slapped on the front of everything, but nothing works...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
错字。 crtl+f 表示“passiveItnerval”...“t”和“n”颠倒了。
另外,如果可能的话,请考虑使用
setTimeout
而不是setInterval
。setInterval
可能会变得很麻烦。Typo. crtl+f for "passiveItnerval"... the "t" and "n" are reversed.
Also, please consider using
setTimeout
instead ofsetInterval
if possible.setInterval
can get hairy.你有一个错字
PassiveItnerval != PassiveInterval
You've got a typo
passiveItnerval != passiveInterval
我有一个简单的函数,你可以一遍又一遍地使用它:
注意:当函数 f() 返回 true 时,即使循环无穷无尽,也可以停止循环,
使用起来非常简单:
想象一下你可以用它做什么,它是无尽的;-)
问候和欢呼,
欧文·汉杰斯
I have a simple function for this and you can use it over and over again:
NOTE: when function f() returns true loop can be stopped even when it is endless
very simple to use:
Imagine what you can do with it, it is endless ;-)
Greetz and cheers,
Erwin Haantjes