Javascript setTimeout 不允许间隔低于 100 毫秒 [英] Javascript setTimeout doesn't allow interval under 100 milliseconds

查看:33
本文介绍了Javascript setTimeout 不允许间隔低于 100 毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每 10 毫秒触发一次递归函数,但无论我输入什么,setTimeout 似乎都没有低于 100 的值.

I want to fire a recursive function every 10 milliseconds, but setTimeout doesn't seem to take any value under 100, no matter what I put.

decrementCountdown = function() {
    console.log('fired');
    t = setTimeout("decrementCountdown()", 100);
}

为什么我不能设置一个低于 1000 毫秒的值?

Why can't I set a value under 1000 milliseconds?

看起来我的计时器正在正确触发......问题是当我使用它来调用一个函数(如 Jquery 的 html() ).即使 setTimeout 以正确的时间间隔调用该函数,它的触发速度也不会超过 100 毫秒.

EDIT : Looks like my timer is firing correctly...the problem is when I use it to call a function ( like Jquery's html() ). Even though setTimeout is calling the function at correct intervals, it won't fire any faster than 100 milliseconds.

有谁知道如何在我的页面上制作一个倒计时 10 毫秒的倒数计时器?

Anyone know how I can make a countdown timer on my page that counts down by 10 milliseconds?

推荐答案

一个更好的例子是:

var stop = 0;
decrementCountdown = function() {
    console.log(new Date().getTime());
    stop++;
    if (stop<10) t = setTimeout("decrementCountdown()", 100);
}

decrementCountdown();

如您所见,超时大约每 100 毫秒触发一次 (jsFiddle).

As you should see, the timeout is triggered about every 100ms (jsFiddle).

这篇关于Javascript setTimeout 不允许间隔低于 100 毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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