用JavaScript动态改变背景颜色。

时间:2022-11-21 12:47:57

In my css a background-color is defined set as white, but I want to change color dynamically body of page.

在我的css中,背景色被定义为白色,但是我想要改变页面的颜色。

How do you do that? my CSS file:

你是怎么做到的?我的CSS文件:

body {
    color: #333;
    background-color: #FFF;
}

my javascript code :

我的javascript代码:

function init() 
{
    document.body.style.zoom="90%";
    document.body.color="white";
}

Thank you.

谢谢你!

2 个解决方案

#1


2  

document.body.style.background = 'yourColor';

How do I change the background color with Javascript?

如何用Javascript改变背景颜色?

#2


1  

For changing the style you need to access the style property, and the property of background-color is backgroundColor

为了改变样式,您需要访问样式属性,背景色的属性是backgroundColor。

 document.body.style.backgroundColor="white"

#1


2  

document.body.style.background = 'yourColor';

How do I change the background color with Javascript?

如何用Javascript改变背景颜色?

#2


1  

For changing the style you need to access the style property, and the property of background-color is backgroundColor

为了改变样式,您需要访问样式属性,背景色的属性是backgroundColor。

 document.body.style.backgroundColor="white"