javascript背景颜色按时变换


<head>

</head>
<body onload="setcolor()" >
<div id=mydiv style="font:12px sans-serif;width:300px;height:200px;">背景色测试</div>
<script>
function setcolor()
{
var colorString;
do{
colorString="#"+Math.floor(Math.random()*Math.pow(2,24)).toString(16);
}
while (colorString.length<7);

document.getElementById("mydiv").style.backgroundColor=colorString;

setTimeout(setcolor,100);
}

</script>
</body>

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3