js 相容性封裝讀取css樣式的函式

2021-09-26 03:55:23 字數 579 閱讀 2756

高階瀏覽器: chrome firefox ie9及以上符合web標準瀏覽器。

低版本瀏覽器: ie6,ie7,ie8。

getcomputedstyle和currentstyle二者的適用範圍:

getcomputedstyle只能高階瀏覽器使用,ie低版本不能使用。

currentstyle ie瀏覽器都能使用。

解決方案:高階瀏覽器用getcomputedstyle,ie低版本currentstyle。

由於getcomputedstyle只能高階瀏覽器使用,所以說在高階瀏覽器的window物件下有getcomputedstyle的方法。在ie低版本中使用getcomputedstyle,會報錯,所以window.getcomputedstyle作為區分要點,因為在高階瀏覽器中有這個屬性,在低版本瀏覽器中相當於在window下新增了乙個getcomputedstyle屬性,沒有賦值,為undefined。

引數1:所要讀採樣式的標籤名

引數2:所要讀取的css樣式名

function getstyle(obj,pro)else

}呼叫函式:getstyle(box,『width』);

css樣式獲取及相容性(原生js)

類選擇器相容性 getbyclass 類選擇器,在ie8及以下均不可用。類選擇器的相容性 function getbyclass parentname,name ie9及以上支援,一下為undified else ie瀏覽器 var odivcss getcssstyle odiv alert od...

css3 常見相容性樣式

引言 由於各瀏覽器製造商遵尋各自不同的規則,使得瀏覽器渲染的差異性,並且個瀏覽器對css3的支援度不同,引發出頁面渲染的相容性問題。如何能夠使前端頁面在不同瀏覽器渲染出相同的效果,成為前端工程師不得不考慮的問題。下面就css3樣式給出一些解決相容性問題的方法 當下主流的瀏覽器及其核心 瀏覽器 核心g...

CSS相容性總結

一.針對ie6的 important 必須寫在前面,例如 background 9c6 important background 999 二.css hack ie6 專用 height 100px ie7 專用 height 100px ie6 ie7 共用 height 100px ie7 ff...