1. 程式人生 > >獲取元素的CSS樣式屬性值 IE相容寫法

獲取元素的CSS樣式屬性值 IE相容寫法

/**
* 獲取元素的CSS樣式屬性值
*/
function css(element, attrName) {
  /*if (window.getComputedStyle)
  return window.getComputedStyle(element)[attrName]
  return element.currentStyle[attrName];*/

  return window.getComputedStyle ? getComputedStyle(element)[attrName]: element.currentStyle[attrName];
}