s[1]=Math.floor(Math.random()*256)+""
s[2]=Math.floor(Math">

网页实用技巧:随机显示不同页面背景

80酷酷网    80kuku.com

  技巧|随机|网页|显示|页面

运行时,按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"
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='按钮' LANGUAGE="JavaScript">
bg = new Array(3); //设定图片数量2
bg[1] = 'icon/1.gif' //显示的图片路径
bg[2] = 'icon/2.gif'
bg[3] = 'icon/3.gif'
index = Math.floor(Math.random()*bg.length);
document.write("<BODY BACKGROUND="+bg[index]+">");
</script> -



分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: