Ste*_*eve 0 html javascript dom
我在这里有一个jsfiddle - http://jsfiddle.net/stevea/R3z2j/2/ - 我在样式表中将红色背景应用到了身体,但是当我在DOM中查看body的样式节点时
style = document.body.style;
bgclr = document.body.style.backgroundColor;
Run Code Online (Sandbox Code Playgroud)
那里没有任何背景颜色.
谢谢
详细说明我的评论......
element.style" 表示元素的样式属性 ",或者从style属性或直接操作中表示元素自己的样式.
要获取元素实际使用的样式(包括继承),您可以getComputedStyle()在大多数浏览器(可选getPropertyValue())和element.currentStyleoldIE中使用:
window.getComputedStyle(document.body).backgroundColor
window.getComputedStyle(document.body).getPropertyValue('background-color')
document.body.currentStyle.backgroundColor
Run Code Online (Sandbox Code Playgroud)
或者,既然你正在使用jQuery,你也可以使用.css(propertyName):
$(document.body).css('background-color');
Run Code Online (Sandbox Code Playgroud)