jsfunction setRadBg()
{
bg = new Array(4); //设定图片数量,如果图片数为3,这个参数就设为2,依次类推
bg[0] = '1.gif' //显示的图片路径,可用http://
bg[1] = '2.gif'
bg[2] = '3.gif'
bg[3] = '4.gif'
bg[4] = '5.gif'
index = Math.floor(Math.random() * bg.length);
document.body.style.background = bg[index];
}<body onload="setRadBg;">改成这样试试
未经测试

解决方案 »

  1.   

    漏了个括号
    <body onload="setRadBg();">
      

  2.   

    common.js:
    function set_bg(){
       bg = new Array(4); //设定图片数量,如果图片数为3,这个参数就设为2,依次类推
       bg[0] = '1.gif'    //显示的图片路径,可用http://
       bg[1] = '2.gif'
       bg[2] = '3.gif'
       bg[3] = '4.gif'
       index = Math.floor(Math.random() * bg.length);
       return bg[index];
     }
    web页面:
    <html>
    <head>
    </head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head>
    <body onload='this.background=set_bg();'>
    </body>
    </html>
      

  3.   

    <html>
    <head><script LANGUAGE="JavaScript">
    bg = new Array(4); //设定图片数量,如果图片数为3,这个参数就设为2,依次类推
    bg[0] = '1.gif' //显示的图片路径,可用http://
    bg[1] = '2.gif'
    bg[2] = '3.gif'
    bg[3] = '4.gif'
    bg[4] = '5.gif'
    index = Math.floor(Math.random() * bg.length);
    document.body.background="+bg[index];
    </script><meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body></body>
    </html>
      

  4.   

    我的意思是这样的:这个是QQ空间换背景的代码<img src="javas&#99;ript:document.getElementById('all').style.background='url(地址)';">
    这个地址里面该怎么写 我要调用的是上面的5个图片 ,高手指点 谢谢
      

  5.   

    <script>
    function set_bg(){
       bg = new Array(4); //设定图片数量,如果图片数为3,这个参数就设为2,依次类推
       bg[0] = '1.gif'    //显示的图片路径,可用http://
       bg[1] = '2.gif'
       bg[2] = '3.gif'
       bg[3] = '4.gif'
       index = Math.floor(Math.random() * bg.length);
       return bg[index];
     }
    </script><img src="set_bg();">
    这样的?
      

  6.   

    jsfunction setRadBg()
    {
    bg = new Array(4); //设定图片数量,如果图片数为3,这个参数就设为2,依次类推
    bg[0] = '1.gif' //显示的图片路径,可用http://
    bg[1] = '2.gif'
    bg[2] = '3.gif'
    bg[3] = '4.gif'
    bg[4] = '5.gif'
    index = Math.floor(Math.random() * bg.length);
    document.body.style.background = bg[index];
    }<body onload="setRadBg;">body onload='this.background=bg();'>