简体   繁体   中英

How do you change the background color of an webpage with JS?

I have this script that here that I'll program later to continously change the background color, but for some reason it does not work at all. It's not throwing any errors either

<html>
<body id = "BGCOLOR" bgcolor = rgb(0,0,0); >
<script>
function ChangeColor(){
    document.getElementById("BGCOLOR").bgcolor = "rgb(0,50,0)";
}
ChangeColor();
</script>
</body>
</html>
document.body.style.backgroundColor = "red";

有关更多参考,请访问http://www.w3schools.com/jsref/prop_style_backgroundcolor.asp

friend try this code

 <html>
    <body id = "BGCOLOR" bgcolor = rgb(0,0,0); >
    <script>
    function ChangeColor(){
        document.body.style.backgroundColor = "rgb(0,50,0)";
    }
    ChangeColor();
    </script>
    </body>
    </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM