JavaScript 取得最终样式

来源:互联网 发布:sd卡损坏 数据恢复 编辑:程序博客网 时间:2024/05/20 02:55

IE

Microsoft offers a currentStyle object on each element that includes all properties from the element.

The currentStyle object works in the exact same way as the style object, with all the same properties and methods. This means that even if a background color is defined in a CSS rule, currentStyle.backgroundColor still contains the correct value.
 

 

DOM

The DOM provides a method called getComputedStyle() that creates a style-like object based on a given element. The method accepts two parameters, the element to get the style for and a pseudo-element,such as :hover or :first-letter (it can also be null if not needed). You can access this method from the document.defaultView object, which is used to represent the currently rendered view of the document(document.defaultView is not supported in Internet Explorer or Safari).