随机变色
2015-01-25 10:08:14 -0500
<script>
function randomColor() {
//16进制方式表示颜色0-F
var arrHex = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];
var strHex = "#";
var index;
for(var i = 0; i < 6; i++) {
//取得0-15之间的随机整数
index = Math.round(Math.random() * 15);
strHex += arrHex[index];
}
return strHex;
}
function test(){
var bgColor = randomColor();
//改变背景色的代码
var myBackground = document.getElementById("whole_body");
//改变背景色的区域
myBackground.style.backgroundColor = bgColor;
}
</script>
<body onLoad="test()">
Back to home
Subscribe |
Register |
Login
| N