当前位置:编程学习 > JS >>

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需刷新才能执行]

上一个:js之点击 超连接,提示一个层.点击空白.层消失
下一个:textContent在Firefox下与innerText等效的属性

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,