与document.defaultView.getComputedStyle和window.getComputedStyle有什么区别 [英] what's the difference bewteen document.defaultView.getComputedStyle and window.getComputedStyle

查看:105
本文介绍了与document.defaultView.getComputedStyle和window.getComputedStyle有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获取元素的样式时,我们总是使用

when get a element's style, we always use

if(document.defaultView&& document.defaultView.getComputedStyle)检查浏览器是否支持该方法。

if(document.defaultView && document.defaultView.getComputedStyle) to check whether the browser support the method or not.

为什么不使用 if(window.getComputedStyle)

推荐答案

简而言之,我们之所以使用 document.defaultView&& ; document.defaultView.getComputedStyle 是我们想要一个跨浏览器的每个元素的工作方法来检查它何时支持获取计算样式。

So in short, the reason why we use document.defaultView && document.defaultView.getComputedStyle is that we want a cross-browser working-on-every-element method of checking whenever it supports fetching computed styles.

简单 if(window.getComputedStyle)对于Firefox 3.6中的iframe会失败(根据文章链接

Simple if(window.getComputedStyle) would fail for iframes in Firefox 3.6 (according to article linked in comment by Alex K.).

这篇关于与document.defaultView.getComputedStyle和window.getComputedStyle有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆