简体   繁体   English

如何使用JS更改网页的背景颜色?

[英]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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 JS 中更改背景颜色? - How do I change a background color in JS? Vue.js:如何根据 data.table 行中项目的值更改图标和背景颜色? - Vue.js: How do you change an icon and background color depending on the value of an item in a data table row? 如何更改 CSS 中 td 的背景颜色? - How do you change background color on td in CSS? 如何通过在Javascript中进行悬停将背景色更改为特定的类 - How do you change a background color to a specific class with hovering in Javascript 如何更改网格列的整个列背景颜色? - How do you change the entire column background color of a grid column? 在网页jQuery上更改背景颜色 - change background color on webpage jQuery 当发生特定情况时,如何更改html表条目背景的背景颜色? - How do you change the background color of an html table entry background when something specific happens? 如何使用json api随机更改网页的背景颜色? - How to change the background color of webpage randomly using a json api? 如何在 javascript 中获取网页上特定像素的颜色? (没有画布) - How do you get the color of a specific pixel on a webpage in javascript? (no canvas) 如何在不更改CSS背景的情况下正确更改Fontello图标的颜色 - How do you properly change a Fontello icon color without changing the background in CSS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM