實用技巧:隨機顯示不同頁面背景
更新時間:2012-01-24 | 發(fā)布人:本站 | 點擊率:284 次
<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='按鈕' style=background-color:"+s[i]+">")
</script>
隨機顯示圖片:
將以下代碼加在<head>與</head>之間。
<script LANGUAGE="JavaScript">
bg = new Array(3); //設(shè)定圖片數(shù)量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>