此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

Document:bgColor 属性

Deprecated

Avoid using this feature in new projects. Document color attributes are superseded by CSS. This feature may be a candidate for removal from web standards or browsers.

Consider using the following features instead: background-colorColorCSS object modelgetComputedStyle().

已弃用的 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 替代方法。

规范

规范
HTML
# dom-document-bgcolor

浏览器兼容性