![](/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.