JavaScript中的睡眠功能 [英] Sleep function in javascript

查看:92
本文介绍了JavaScript中的睡眠功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

javascript中是否可以使用类似于休眠功能的任何方法. SetTimeOut和SetIntervalTime在我的情况下将无效,并且基于时间的循环还会导致5秒钟后脚本无响应对话框.我想睡30秒.请帮忙.

Is there any method in javascript that can be used similar to sleep function. SetTimeOut and SetIntervalTime will not be effective in my case, Also Loop based on time will cause script non responsive dialog after 5 second. I want a sleep for 30 Second. Please help.

推荐答案

function wait(msecs)
{
var start = new Date().getTime();
var cur = start
while(cur - start < msecs)
{
cur = new Date().getTime();
} 
} 

to use:

alert(\"Will wait for one second\");
wait(30000);
alert(\"Finished waiting\");



希望对您有所帮助!



Hope this helps!


请参阅此处"DevCheater.com-javascript睡眠" [ ^ ]
为什么在JavaScript中睡觉通常是个坏主意.
See here "DevCheater.com - javascript sleep"[^]
why sleep in JavaScript it is usually a bad idea.


这篇关于JavaScript中的睡眠功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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