如何使用 clearTimeout [英] How to use clearTimeout
本文介绍了如何使用 clearTimeout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 javascript 和 Meteor 的新手,并试图清除函数的函数的超时.
I am new to javascript and Meteor and trying to clearTimeout on a function of a function.
控制台状态找不到属性.我没有写代码,所以我不知道如何停止计时器.
The console states cannot find property of. I did not write the code so I am at a loss of how to stop the timer.
感谢任何建议!代码:
function startTimer(){
start = new Date().getTime();
time = 0;
elapsed = '0.0';
function instance(){
time += 100;
console.log('instance started');
elapsed = Math.floor(time / 100) / 10;
if(Math.round(elapsed) == elapsed) { elapsed += '.0'; }
document.title = elapsed;
var diff = (new Date().getTime() - start) - time;
window.setTimeout(instance, (100 - diff));
};
window.setTimeout(instance, 100);
};
function stopTimer() {
clearTimeout();
};
推荐答案
// define myTimeout somewhere globally
var myTimeout;
function instance() {
...
myTimeout = setTimeout(instance, 100);
}
function stop() {
clearTimeout(myTimeout);
}
这篇关于如何使用 clearTimeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文