Document:bgColor 属性

已弃用: 不再推荐使用该特性。虽然一些浏览器仍然支持它,但也许已从相关的 web 标准中移除,也许正准备移除或出于兼容性而保留。请尽量不要使用该特性,并更新现有的代码;参见本页面底部的兼容性表格以指导你作出决定。请注意,该特性随时可能无法正常工作。

已弃用的 bgColor 属性用于获取或设置当前文档的背景颜色。

表示颜色的字符串,可以是颜色名称(例如“red”)或十六进制值(例如“#ff0000”)。

示例

js
document.bgColor = "darkblue";

备注

Firefox 中该属性的默认值是白色(十六进制的 #ffffff)。

DOM 第 2 版 HTML 规范中 document.bgColor 已被弃用。推荐的替代方法是使用 CSS 样式 background-color,可以通过 DOM 中的 document.body.style.backgroundColor 来访问该样式。另一种替代方法是 document.body.bgColor,不过 HTML 4.01 也已弃用这种方法,转而使用 CSS 替代方法。

规范

Specification
HTML
# dom-document-bgcolor

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
bgColor
Deprecated

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
Deprecated. Not for use in new websites.
Has more compatibility info.