不行吗?是不是在打开这个网页的目录里放入1.gif 2.gif 3.gif啊?
好像不可以吗?但是也没有报错,就是效果实现不了

解决方案 »

  1.   

    问题在于document.write(bg[index].bgColor+" "+bg[index].bgImg);
    document.write之后,你可以查看源代码,已经不是原来的文件了
    所以不会重复a();
    只能执行一次
    另外我建议你这么写最好
    你那样写容易死循环<script language="javascript">
    var bg=new Array();
    bg[0]={bgColor:'blue',bgImg:'1.gif'}
    bg[1]={bgColor:'red',bgImg:'2.gif'}
    bg[2]={bgColor:'green',bgImg:'3.gif'}
    function a(){
    //    alert('test');
    index = Math.floor(Math.random()*bg.length);
    document.body.bgColor=bg[index].bgColor;
       document.body.background="icon/icon"+bg[index].bgImg;
    }
    setInterval("a()",1000);
    </script>
      

  2.   

    谢谢!
    小问题,
    <script language="javascript">
    var bg=new Array();
    bg[0]={bgColor:'blue',bgImg:'1.gif'}
    bg[1]={bgColor:'red',bgImg:'2.gif'}
    bg[2]={bgColor:'green',bgImg:'3.gif'}
    function a(){
    //    alert('test');
    index = Math.floor(Math.random()*bg.length);
    document.body.bgColor=bg[index].bgColor;
       document.body.background="你的目录"+bg[index].bgImg;
    setTimeout("a()",1000)}
    window.onload=a()
    </script>
    他说网页里有错误,但我不知道是那里错了,请告知,谢谢!