首页 > IE的cssText值为空?

IE的cssText值为空?

前提

首先这里的 cssText 并非 element.style.cssText

过程

  1. document.defaultView.getComputedStyle(element)
    方式一获取CSSStyleDeclaration只读对象

  2. element.currentStyle
    方式二获取CSSStyleDeclaration只读对象, for:IE

  3. window.getComputedStyle(element)
    方式二获取CSSStyleDeclaration只读对象, for:通用

以上3种方式获取的CSSStyleDeclaration对象的cssText属性, 在Chrome下正常,
但是在IE下却是空字符串. 能测试的 IE7 ~ Edge 都是如此.

提问

var cssText = window.getComputedStyle(element).cssText;
chrome下的结果就是我想要的, 如何获取到呢?


我记得好像IE不支持window.getComputedStyle,要获取IE下的cssText可以通过element.currentStyle.cssText

【热门文章】
【热门文章】