<html> <head> <title>随机改变背景颜色(自动变化)</title> <style> #bg{ width:200px; height:200px; } </style> </head> <body> <div id="bg"></div> <script> function changeBg(){ var bg=document.getElementById("bg"); var rand=Math.round(Math.random()*1000000); bg.style.backgroundColor="#"+rand; } setInterval("changeBg();",1000); </script> </body></html>
版权声明
本文仅代表作者观点,不代表百度立场。
本文系作者授权百度百家发表,未经许可,不得转载。



