樣式獲取
style屬性 只能獲取標簽內容style屬性里面存在的一些樣式
如果你需要獲取對應的全域所有地方設定樣式 我們就需要采用一些方法
getComputedStyle 方法屬于window的方法
Window.getComputedStyle()方法回傳一個物件,該物件在應用活動樣式表并決議這些值可能包含的任何基本計算后報告元素的所有 CSS 屬性的值,
window.getComputedStyle(元素物件,null) //回傳給你的是一個樣式物件
ie兼容
element.currentStyle //回傳給你一個樣式物件
兼容封裝
//方法的封裝 function getStyle(element,attr){ var style = window.getComputedStyle?window.getComputedStyle(element):element.currentStyle return style[attr] } //呼叫 console.log(getStyle(box,'height'));
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/508159.html
標籤:JavaScript
上一篇:事件流
