简体   繁体   English

清除设置超时 Javascript

[英]Clear Set TimeOut Javascript

I am creating Tabs in javascript in my ASP.Net web site.我在我的 ASP.Net web 站点的 javascript 中创建选项卡。 Say Tab 1 Tab 2--- Tab 10. When I click on Tab 1 it shows some data and I call setTimeout function that keeps refreshing the Tab 1 data.说 Tab 1 Tab 2--- Tab 10。当我单击 Tab 1 时,它会显示一些数据,我调用 setTimeout function 来不断刷新 Tab 1 数据。 My problem is when i switch to other tabs the settimeout function still keep running in the background, that i don't want.我的问题是当我切换到其他选项卡时,settimeout function 仍然在后台运行,这是我不想要的。 How can i stop this on moving to other tabs.我如何才能停止移动到其他选项卡。

Thanks谢谢

Regards Vivek问候维韦克

You could use the clearTimeout function.您可以使用clearTimeout function。 Example:例子:

var timeoutHandle = window.setTimeout(function() {
    // ...
}, 5000);

and later you could:后来你可以:

window.clearTimeout(timeoutHandle);

There are also the setInterval / clearInterval methods which could be used.还有可以使用的setInterval / clearInterval方法。 Contrary to setTimeout , the setInterval function executes the callback multiple times until cleared.setTimeout相反, setInterval function 多次执行回调直到被清除。 A similar behavior could be achieved with setTimeout by recursively calling the callback.通过递归调用回调,可以使用setTimeout实现类似的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM