Tag Archives: currentStyle

Javascript获取CSS值

IE: element.currentStyle currentStyle 对象返回了元素上的样式表,但是 style 对象只返回通过 style 标签属性应用到元素的内嵌样式。因此,通过 currentStyle 对象获取的样式值可能与通过 style 对象获取的样式值不同。例如,如果段落的 color 属性值通过链接或嵌入样式表设置为红色( red ),而不是内嵌的话,对象.currentStyle.color 将返回正确的颜色,而对象 style.color 不能返回值。但是,如果用户指定了 <P STYLE="color:’red’">,currentStyle 和 STYLE 对象都将返回值 red。 currentStyle 对象反映了样式表中的样式优先顺序。在 HTML 中此顺序为: 内嵌样式 样式表规则 HTML 标签属性 HTML 标签的内部定义 W3C: window.getComputedStyle(element,pseudoElt) element 必选,HTML元素 pseudoElt 必选,获取该元素的伪类样式 关于获取css的浏览器兼容: http://www.quirksmode.org/dom/w3c_css.html jQuery里关于获取CSS的实现: function( elem, name, force ) { var ret, style = elem.style, [...]