网页上的计时器 [英] Timer on webpages

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

问题描述




我不知道在哪里找到我需要的所有文件?我需要

来计时器,因为已按下启动按钮,并在

页面上显示计数器。如果他们点击停止我想保留时间,并继续

如果他们再次点击开始递增它。


对代码或参考资料的任何建议为此?


感谢所有帮助


David

解决方案

2006-04-29,David< da ************ @ gmail.com>写道:



我不知道在哪里可以找到我需要的所有文档?我需要
定时器,因为按下了一个开始按钮,并在
页面上显示一个计数器。如果他们点击停止我想保留时间,并继续点击,如果他们再次点击开始增加它。

有关代码或参考资料的任何建议吗?




棘手的一个。我不能想到除了使用setInterval之外的一种方式,

的间隔大约是一秒钟。在回调中,你更新计数器,

动画等,并增加一个变量,计算已经过了多少秒。


Ben C在2006年4月29日上午11:53发表以下内容:

2006-04-29,David< da ********* ***@gmail.com>写道:



我不知道在哪里可以找到我需要的所有文档?我需要
定时器,因为按下了一个开始按钮,并在
页面上显示一个计数器。如果他们点击停止我想保留时间,并继续点击再次点击开始增加它。

有关代码或参考资料的任何建议吗?
Tricky一个。




不是真的。

除了使用setInterval,我想不出办法,


还有其他方法,但setInterval是更新

页面本身的最佳方式。不一定是增加计数器的最好方法。

,间隔大约一秒钟。


你用于setInterval的分辨率将取决于你愿意使用多少资金以及你想要的准确度

计时器时间明智。

在回调中你更新计数器,动画等,然后递增一个计算已经过了多少秒的变量。




我不同意那个。增加一个变量会导致总计不准确
。刚开始使用Date对象并比较

当前时间,得到差异,然后显示它。


这个问题和其他任何一个的唯一区别;运行计数器

问题是开始/停止按钮。你如何处理这些将直接取决于OP是否希望计时器包括

停止时间。


-

兰迪

comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组每周

Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /


JRS:文章< mM ******************* ***********@comcast.com> ;,日期

星期六,2006年4月29日14:34:28远程,见于新闻:comp.lang.javascript,

Randy Webb< Hi ************ @ aol.com>发布:

在回调中,您更新计数器,动画等,并增加一个计算已经过了多少秒的变量。


我不同意那个。增加变量会导致总数不准确。只需从Date对象开始,比较
当前时间,获取差异,然后显示它。




使用日期对象指示持续时间将不可靠在系统中

,其中时钟会不时自动同步。


天真地使用日期对象来指示持续时间将不可靠

夏季和冬季之间的季节变化。


-

?约翰斯托克顿,英国萨里。 ?@merlyn.demon.co.uk Turnpike v4.00 MIME。 ?

Web< URL:http://www.merlyn.demon.co.uk/> - w。常见问题主题,链接,首字母缩略词

PAS EXE等:< URL:http://www.merlyn.demon.co.uk/programs/> - 见00index.htm

日期 - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm等


Hi,

Im not sure where to find all the documentation i need for this? I need
to timer since a start button has been pushed, and show a counter on a
page. If they click stop i want to keep the time, and carry on
incrementing it if they click start again.

Any suggestions on code, or reference material for this?

Thanks for all the help

David

解决方案

On 2006-04-29, David <da************@gmail.com> wrote:

Hi,

Im not sure where to find all the documentation i need for this? I need
to timer since a start button has been pushed, and show a counter on a
page. If they click stop i want to keep the time, and carry on
incrementing it if they click start again.

Any suggestions on code, or reference material for this?



Tricky one. I can''t think of a way except using setInterval, with an
interval of about a second. In the callback you update the counter,
animation, etc., and increment a variable that counts how many seconds have
elapsed.


Ben C said the following on 4/29/2006 11:53 AM:

On 2006-04-29, David <da************@gmail.com> wrote:

Hi,

Im not sure where to find all the documentation i need for this? I need
to timer since a start button has been pushed, and show a counter on a
page. If they click stop i want to keep the time, and carry on
incrementing it if they click start again.

Any suggestions on code, or reference material for this?
Tricky one.



Not really.
I can''t think of a way except using setInterval,
There are other ways but setInterval would be the best way to update the
page itself. Not necessarily the best way to increment the counter though.
with an interval of about a second.
The resolution you used for setInterval would depend on how much
resource you would be willing to use and how accurate you wanted the
counter time wise.
In the callback you update the counter, animation, etc.,
and increment a variable that counts how many seconds have elapsed.



I don''t agree with that one. Incrementing a variable would lead to
inaccuracies in the total. Just start with a Date object and compare the
current time, get the difference, and display it.

The only difference in this question and any other "running counter"
question is the Start/Stop buttons. And how you handled those would
depend, directly, on whether the OP wanted the timer to include the
Stopped time or not.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


JRS: In article <mM******************************@comcast.com>, dated
Sat, 29 Apr 2006 14:34:28 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :

In the callback you update the counter, animation, etc.,
and increment a variable that counts how many seconds have elapsed.



I don''t agree with that one. Incrementing a variable would lead to
inaccuracies in the total. Just start with a Date object and compare the
current time, get the difference, and display it.



Using a Date Object to indicate duration will be unreliable in systems
where the clock is being automatically synchronised from time to time.

Using a Date Object naively to indicate duration will be unreliable when
the season changes between Summer and Winter.

--
? John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ?
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.


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

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