javascript定时器循环 [英] javascript timer loop

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

问题描述

我想创建一个计时器,一旦达到某个点,计时器就会重置,然后重新开始.

I want to create a timer that once it reaches a certain point, the timer resets, and then starts over.

现在,我已经设置了循环,作为测试,我希望它在 5000 毫秒(5 秒)后重置.但柜台完全出问题了.

Right now, I've got the loop set up, and as a test I want it to reset after 5000 ms (5 seconds). But the counter goes all haywire.

WIP 演示在这里:http://jsfiddle.net/stursby/wUHA3/

推荐答案

考虑使用 setInterval 代替 setTimeout.它会自动重复,直到您清除间隔.

Instead of setTimeout, consider using setInterval. It will repeat automatically until you clear the interval.

setInterval(myMethod, 5000);

function myMethod( )
{
  //this will repeat every 5 seconds
  //you can reset counter here
}

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

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