javascript等待 [英] javascript wait

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

问题描述

我已经收集到javascript没有方便的wait()函数,所以

我做了以下函数makeDelay()来利用PHP的sleep() ,

然后等待,并以完成回复...我的问题是

,javascript不等待makeDelay(秒)到完成......?


makeDelay(5);

iDontWaitForNobody();


函数makeDelay(秒){


url =" make_delay.php?delay =" +秒;

http.open(" GET",url,true);


loadStatus = document.getElementById(" loadStatus");


http.onreadystatechange = function(){

if(http.readyState == 1){

loadStatus.src =" ; balls / load1.gif" ;;

}

if(http.readyState == 2){

loadStatus.src =" balls /load2.gif" ;;

}

if(http.readyState == 3){

loadStatus.src =" balls / load3 .gif" ;;

}

if(http.readyState == 4){

if(http.responseText ==" done" )

loadStatus.src =" balls / load0.gif" ;;

}

}

http。发送(null);

}

解决方案

st ************ @ gmail.com 写道:


我已经收集到javascript没有方便的wait()函数,所以

我使用了以下函数makeDelay()来使用PHP的

sleep(),然后等待,并以done响应...我的

问题是javascript不等待makeDelay(秒)来完成

完成......?



不要这样做。

使用setTimeout();


case:

setTimeout(" iDontWaitForNobody()",5000);

-

Rik Wasmus



st *********** *@gmail.com 写道:


我已经收集了javascript没有方便的wait()函数,



我想你可能正在寻找JavaScript的setTimeout()


彼得




Rik写道:

st ************ @ gmail.com 写道:


我已经收集到javascript没有方便的wait()函数,所以

我做了以下函数makeDelay()来利用PHP的

睡眠( ),然后等待,并用完成回复...我的

问题是javascript不等待makeDelay(秒)

完成.. 。?



不要这样做。

使用setTimeout();


在此case:

setTimeout(" iDontWaitForNobody()",5000);



甚至只是


setTimeout(iDontWaitForNobody,5000);


I''ve gathered that javascript doesn''t have a handy wait() function, so
I made the following function makeDelay() to make use of PHP''s sleep(),
which then does the waiting, and responds with "done"...my problem is
that the javascript doesn''t wait for makeDelay(seconds) to finish...?

makeDelay(5);
iDontWaitForNobody();

function makeDelay(seconds) {

url="make_delay.php?delay=" + seconds;
http.open("GET",url,true);

loadStatus=document.getElementById("loadStatus");

http.onreadystatechange=function() {
if (http.readyState==1) {
loadStatus.src="balls/load1.gif";
}
if (http.readyState==2) {
loadStatus.src="balls/load2.gif";
}
if (http.readyState==3) {
loadStatus.src="balls/load3.gif";
}
if (http.readyState==4) {
if(http.responseText == "done")
loadStatus.src="balls/load0.gif";
}
}
http.send(null);
}

解决方案

st************@gmail.com wrote:

I''ve gathered that javascript doesn''t have a handy wait() function, so
I made the following function makeDelay() to make use of PHP''s
sleep(), which then does the waiting, and responds with "done"...my
problem is that the javascript doesn''t wait for makeDelay(seconds) to
finish...?

Don''t do that.
Use setTimeout();

In this case:
setTimeout("iDontWaitForNobody()",5000);
--
Rik Wasmus



st************@gmail.com wrote:

I''ve gathered that javascript doesn''t have a handy wait() function,

I think you mightu be looking for JavaScript''s setTimeout()

Peter



Rik wrote:

st************@gmail.com wrote:

I''ve gathered that javascript doesn''t have a handy wait() function, so
I made the following function makeDelay() to make use of PHP''s
sleep(), which then does the waiting, and responds with "done"...my
problem is that the javascript doesn''t wait for makeDelay(seconds) to
finish...?


Don''t do that.
Use setTimeout();

In this case:
setTimeout("iDontWaitForNobody()",5000);

or even just

setTimeout(iDontWaitForNobody, 5000);


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

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