薄熙岸中国一谜:css+js控制随机背景图片的代码怎么写?

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/03 05:29:54

在 <head> 与 </head> 之间加入:

<SCRIPT language=JavaScript>
bg = new Array(2); //设定图片数量,如果图片数为3,这个参数就设为2,依次类推
bg[0] = '../images/b-26.gif' //显示的图片路径,可用http://
bg[1] = '../images/b-19.gif'
bg[2] = '../images/b-3.gif'
index = Math.floor(Math.random() * bg.length);
document.write("<BODY BACKGROUND="+bg[index]+">");
</SCRIPT>