运行时,按F5便可看效果!
<script>
s=new Array(3)
s[0]=Math.floor(Math.random()*256)+""
s[1]=Math.floor(Math.random()*256)+""
s[2]=Math.floor(Math.random()*256)+""
a=s[0]+s[1]+s[2]
document.write("<body bgcolor="+a+">")
document.write("</body>")
</script>
<script>
s="icon/icon"+Math.floor(Math.random()*18)+".gif?http://www.xvna.com"
document.write("<body background="+s+">")
document.write("</body>")
</script>
红绿蓝三种颜色:
<script>
s=new Array(3)
s[0]="ff0000"
s[1]="00ff00"
s[2]="0000ff"
i=Math.floor(Math.random()*3)
document.write("<body bgcolor="+s[i]+">")
document.write("</body>")
</script>
按钮上:
<script>
s=new Array(3)
s[0]="ff0000"
s[1]="00ff00"
s[2]="0000ff"
i=Math.floor(Math.random()*3)
document.write("<input type='button' value='按钮' style=background-color:"+s[i]+">")
</script>
随机显示图片:
将以下代码加在<head>与</head>之间。
<script LANGUAGE="JavaScript">
bg = new Array(3); //设定图片数量2
bg[1] = 'icon/1.gif?http://www.xvna.com' //显示的图片路径
bg[2] = 'icon/2.gif?http://www.xvna.com'
bg[3] = 'icon/3.gif?http://www.xvna.com'
index = Math.floor(Math.random()*bg.length);
document.write("<BODY BACKGROUND="+bg[index]+">");
</script> -