function haha()
{
document.write("这就是设置时间间隔");
}
function doit()
{
alert("好!准备开始了!");
setTimeout(haha,3000);
alert("好!再准备一次!");
setTimeout(haha,3000);
}可程序的结果不能按照设想的那样,它并没有让我等待两个3秒钟!
请问这是怎么回事??
谢谢!
{
document.write("这就是设置时间间隔");
}
function doit()
{
alert("好!准备开始了!");
setTimeout(haha,3000);
alert("好!再准备一次!");
setTimeout(haha,3000);
}可程序的结果不能按照设想的那样,它并没有让我等待两个3秒钟!
请问这是怎么回事??
谢谢!
setTimeout(haha,3000);
alert("好!再准备一次!");
setTimeout(haha,3000);这样是执行了2次haha函数,而不是一起等待2个3秒(加起来6秒)
{
alert("好!准备开始了!");
setTimeout(haha,3000);
alert("好!再准备一次!");
setTimeout(haha,3000);
}
实际上都是等待3秒做的,所以你看到到两个3秒
如果要实现两个三秒,第二处setTimeout的参数要变为6000ms
function doit()
{
alert("好!准备开始了!");
setTimeout(haha,3000);
alert("好!再准备一次!");
setTimeout(haha,6000);
}