常见问题主题 - 如何延迟10秒? [英] FAQ Topic - How do I make a 10 second delay?

查看:67
本文介绍了常见问题主题 - 如何延迟10秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

----------------------------------------------- ------------------------

常见问题解答主题 - 如何延迟10秒?

------------------------------------------------ -----------------------


没有内置的方法可以在javascript中暂停执行/>
作为睡眠功能,但主机通常提供一些形式的b / b
。 Web浏览器专为事件驱动编程而设计,并且
仅提供``setTimeout''''和``setInterval''''函数

以便于定时延迟。


要调用函数``Snork()'''',在函数``Moomin()'''之后大约10秒

,你会这样做:


姆明()

setTimeout(''Snork()'',10000)


脚本执行没有停止,并且在

setTimeout行之后添加``Snufkin()'''将立即执行函数``Snufkin()''''
$ b在$`Snork之前$ b''''


通过运行某种类型的循环来实现延迟

预定义的时间段是不好的策略,因为这将倾向于使用高达100%的CPU使用率并抑制在延迟期间发生的任何事情。


其他(事件驱动较少)主机具有不同的等待功能,

,例如Windows脚本宿主中的``WScript.Sleep()'''。

http://msdn.microsoft.com/workshop/a...setTimeout.asp

http:// docs.sun.com/source/816-6408-...ow.htm#1203758
http://en.wikipedia.org/wiki/Event-driven_programming

===

这样的发布每天自动发送一次。他们的b
目标是回答重复的问题,并将内容提供给社区进行持续评估/改进。完整的

comp.lang.javascript常见问题解答位于 http:/ /www.jibbering.com/faq/

FAQ工作人员是一群志愿者。

解决方案

JRS:文章< 44 *********************** @ news.sunsite.dk>,日期为Fri,
2006年9月1日23:00:02远程,在新闻中看到:comp.lang.javascript,常见问题

服务器< ja ******** @ dotinternet.beposted :


>常见问题解答主题 - 如何延迟10秒?


setTimeout(''Snork()'',10000)



<常见问题>

恕我直言,应该有一个注意事项,呼叫Snork之前的延迟将会超过第二个参数所要求的延迟,因为

实施细节。 < / FAQENT>


< URL:http://www.merlyn.demon.co.uk/js-date0.htm#TaI将显示

效果;它在IE4 / Win98中平均至少27毫秒,在较新的
系统中平均少得多,如果操作系统繁忙,可能会增加。但是,对于类似时钟的

应用程序,应该纠正错误。


FAQ是否会实际更新?

- -

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

< URL:http://www.jibbering.com/faq/>? JL / RC:新闻常见问题:comp.lang.javascript

< URL:http://www.merlyn.demon.co.uk/js-index.htmjscr数学,日期,来源。

< URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/& c,常见问题项目,链接。


-----------------------------------------------------------------------
FAQ Topic - How do I make a 10 second delay?
-----------------------------------------------------------------------

There is no built-in way to pause execution in javascript such
as a sleep function, but hosts usually provide a method of some
form. Web browsers are designed for event driven programming and
only provide the `` setTimeout '''' and `` setInterval '''' functions
to facilitate timed delays.

To call the function `` Snork() '''', approx 10 seconds
after the function `` Moomin() '''', you would do this:

Moomin()
setTimeout(''Snork()'',10000)

Script execution is not stopped, and adding `` Snufkin() '''' after the
setTimeout line would immediately execute the function `` Snufkin() ''''
before `` Snork() ''''

Achieving delays through running a loop of some sort for a
pre-defined period is a bad strategy, as that will tend to
put CPU use up to 100% and inhibit whatever was supposed to
be happening during the delay.

Other (less event driven) hosts have different wait functions,
such as `` WScript.Sleep() '''' in the Windows Script Host.

http://msdn.microsoft.com/workshop/a...setTimeout.asp

http://docs.sun.com/source/816-6408-...ow.htm#1203758

http://en.wikipedia.org/wiki/Event-driven_programming
===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://www.jibbering.com/faq/.
The FAQ workers are a group of volunteers.

解决方案

JRS: In article <44***********************@news.sunsite.dk>, dated Fri,
1 Sep 2006 23:00:02 remote, seen in news:comp.lang.javascript, FAQ
server <ja********@dotinternet.beposted :

>FAQ Topic - How do I make a 10 second delay?

setTimeout(''Snork()'',10000)

<FAQENTRY>
IMHO there should be a note that the delay before calling Snork will
generally exceed that called for by the second parameter, because of
implementation details. </FAQENTRY>

<URL:http://www.merlyn.demon.co.uk/js-date0.htm#TaIwill show the
effect; it averages at least 27 ms in IE4/Win98 and much less in newer
systems, and may well increase if the OS is busy. But, for clock-like
applications, the error should be corrected.

Will the FAQ actually be updated?
--
? John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ?
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.


这篇关于常见问题主题 - 如何延迟10秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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