首先这里的 cssText 并非 element.style.cssText
document.defaultView.getComputedStyle(element)
方式一获取CSSStyleDeclaration只读对象
element.currentStyle
方式二获取CSSStyleDeclaration只读对象, for:IE
window.getComputedStyle(element)
方式二获取CSSStyleDeclaration只读对象, for:通用
以上3种方式获取的CSSStyleDeclaration对象的cssText属性, 在Chrome下正常,
但是在IE下却是空字符串. 能测试的 IE7 ~ Edge 都是如此.
var cssText = window.getComputedStyle(element).cssText;
chrome下的结果就是我想要的, 如何获取到呢?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我记得好像
IE不支持window.getComputedStyle,要获取IE下的cssText可以通过element.currentStyle.cssText