![](/img/trans.png)
[英]How to use getComputedStyle with DOMParser produced document (no defaultView or window objects)?
[英]what's the difference bewteen document.defaultView.getComputedStyle and window.getComputedStyle
当获取元素的样式时,我们总是使用
if(document.defaultView && document.defaultView.getComputedStyle)
检查浏览器是否支持该方法。
为什么不使用if(window.getComputedStyle)
?
所以简而言之,我们使用document.defaultView && document.defaultView.getComputedStyle
的原因是我们想要一个跨浏览器的工作在每个元素上的方法来检查它是否支持获取计算样式。
对于 Firefox 3.6 中的 iframe,简单的if(window.getComputedStyle)
将失败(根据 Alex K. 评论中链接的文章)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.