职业IT人-IT人生活圈

 找回密码
 成为会员
搜索
查看: 1061|回复: 0

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

[复制链接]
牧牛 发表于 2007-8-12 09:59 | 显示全部楼层 |阅读模式
运行时,按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+\">\")

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=&#39;button&#39; value=&#39;按钮&#39; style=background-color:\"+s+\">\")
</script>
随机显示图片:
将以下代码加在<head>与</head>之间。
<script LANGUAGE=\"JavaScript\">
bg = new Array(3); //设定图片数量2
bg[1] = &#39;icon/1.gif&#39; //显示的图片路径
bg[2] = &#39;icon/2.gif&#39;
bg[3] = &#39;icon/3.gif&#39;
index = Math.floor(Math.random()*bg.length);
document.write(\"<BODY BACKGROUND=\"+bg[index]+\">\");
</script> -
您需要登录后才可以回帖 登录 | 成为会员

本版积分规则

QQ|手机版|小黑屋|网站帮助|职业IT人-IT人生活圈 ( 粤ICP备12053935号-1 )|网站地图
本站文章版权归原发布者及原出处所有。内容为作者个人观点,并不代表本站赞同其观点和对其真实性负责,本站只提供参考并不构成任何投资及应用建议。本站是信息平台,网站上部分文章为转载,并不用于任何商业目的,我们已经尽可能的对作者和来源进行了通告,但是能力有限或疏忽造成漏登,请及时联系我们,我们将根据著作权人的要求立即更正或者删除有关内容。

GMT+8, 2024-5-9 04:57 , Processed in 0.111312 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表