Style backgroundColor 属性
实例
设置文档的背景颜色:
document.body.style.backgroundColor="#f3f3f3";
定义和用法
backgroundColor 属性设置或返回元素的背景颜色。
浏览器支持
![]()
![]()
![]()
![]()
![]()
所有主要浏览器都支持 backgroundColor 属性。
注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有规定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。
语法
设置 backgroundColor 属性:
element.style.backgroundColor="color|inherit|transparent"
返回 backgroundColor 属性:
element.style.backgroundColor
属性值
| 值 | 描述 |
|---|---|
| color | 规定背景颜色。在 CSS 颜色值中寻找可能的颜色值的完整列表。 |
| inherit | 背景颜色从父元素继承。 |
| transparent | 默认。背景颜色是透明的(基本内容将会穿透)。 |
技术细节
| 默认值: | transparent |
|---|---|
| 返回值: | 一个代表背景颜色的字符串 |
| DOM 版本 | Core Level 1 |
Style 对象
