javascript背景颜色按时变换

2018-10-15 17:30

阅读:480

<head>

</head>
<bodyonload=setcolor()>
<divid=mydivstyle=font:12pxsans-serif;width:300px;height:200px;>背景色测试</div>
<script>
functionsetcolor()
{
varcolorString;
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需刷新才能执行]


评论


亲,登录后才可以留言!