本文介绍了reset setInterval()的定时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var timer;
chat.client.addMessage = function (data) {
clearTimeout(timer);
test2(data);
};
timer = setInterval(function () {
console.log("working");
test1();
}, 5000);
我正在尝试在执行chat.client.addMessage时重新启动计时器。每次执行后都执行.InterInterval执行该方法时执行chat.client.addMessage的时间为5000毫秒setInterval函数停止执行。帮助将不胜感激:)
I am trying to restart timer when ever chat.client.addMessage is executed.SetInterval is executed after every 5000ms until chat.client.addMessage is executed when ever that method is executed setInterval Function stops executing . Help will be appreciated:)
推荐答案
您需要使用而不是 clearTimeout
,因为clearTimeout是。你可以用同样的方式使用它:
You need to use clearInterval instead of clearTimeout
as clearTimeout is the inverse of setTimeout. You can use it in the same manner:
clearInterval(timer);
这篇关于reset setInterval()的定时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!