[英]Why isn't the background color changing?
I have javacript code that simply runs我有简单运行的 javacript 代码
document.bgColor = "darkblue";
per每
Mozilla Documentation , however when I step throught the IE debugger, after executing that line the back ground color does not change. Mozilla 文档,但是当我单步执行 IE 调试器时,在执行该行之后,背景颜色不会改变。
Seems pretty straight forward.看起来很简单。 I'm assuming that bgColor refers to the CSS attribute background-color under the element body?
我假设 bgColor 是指元素主体下的 CSS 属性背景颜色?
I can post the surrounding code if that helps.如果有帮助,我可以发布周围的代码。
This page has a large "deprecated" at the top of it.此页面顶部有一个很大的“已弃用”。 You should use the current method:
您应该使用当前方法:
document.body.style.backgroundColor = 'darkblue';
This is stated in the MDN page you cited:这在您引用的 MDN 页面中有说明:
document.bgColor
is deprecated in DOM Level 2 HTML.document.bgColor
在 DOM 级别 2 HTML 中已弃用。 The recommended alternative is use of the CSS style background-color which can be accessed through the DOM withdocument.body.style.backgroundColor
.推荐的替代方法是使用 CSS 样式的背景颜色,可以使用
document.body.style.backgroundColor
通过 DOM 访问。 Another alternative isdocument.body.bgColor
, although this is also deprecated in HTML 4.01 in favor of the CSS alternative.另一种选择是
document.body.bgColor
,尽管这在 HTML 4.01 中也被弃用,取而代之的是 CSS 替代方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.