function haha()
{
document.write("这就是设置时间间隔");
}
function doit()
{
alert("好!准备开始了!");
setTimeout(haha,3000);
alert("好!再准备一次!");
setTimeout(haha,3000);
}可程序的结果不能按照设想的那样,它并没有让我等待两个3秒钟!
请问这是怎么回事??
谢谢!

解决方案 »

  1.   

    alert("好!准备开始了!");
    setTimeout(haha,3000);
    alert("好!再准备一次!");
    setTimeout(haha,3000);这样是执行了2次haha函数,而不是一起等待2个3秒(加起来6秒)
      

  2.   

    等待3秒钟执行的是haha函数,但是你执行了第一次haha后,页面被document.write了,第二次的效果也没了。你改成alert("这就是设置时间间隔");就可以看到效果了
      

  3.   

    function doit()
    {
    alert("好!准备开始了!");
    setTimeout(haha,3000);
    alert("好!再准备一次!");
    setTimeout(haha,3000);
    }
    实际上都是等待3秒做的,所以你看到到两个3秒
    如果要实现两个三秒,第二处setTimeout的参数要变为6000ms
    function doit()
    {
    alert("好!准备开始了!");
    setTimeout(haha,3000);
    alert("好!再准备一次!");
    setTimeout(haha,6000);
    }