javascript:清除所有超时? [英] javascript: Clear all timeouts?

查看:128
本文介绍了javascript:清除所有超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法清除特定窗口的所有超时?我想超时存储在窗口对象的某处,但无法确认。

Is there a way to clear all time outs from a given window? I suppose the timeouts are stored somewhere in the window object but couldn't confirm that.

任何跨浏览器解决方案欢迎。

Any cross browser solution is welcome.

推荐答案

它们不在窗口对象中,但它们有id,其中(afaik)是连续的整数。

They are not in the window object, but they have ids, which (afaik) are consecutive integers.

因此您可以清除所有超时:

So you may clear all timeouts like so:

var id = window.setTimeout(function() {}, 0);

while (id--) {
    window.clearTimeout(id); // will do nothing if no timeout with id is present
}

这篇关于javascript:清除所有超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆