經過JS獲取CSS屬性的值

/**
 * 2013-08-04-經過JS獲取CSS屬性的值
 * [div description]
 * @type {[type]}
 */
var div = document.getElementById("mydiv");
//1.獲取行內樣式表中CSS的值
alert(div.style.width);
//2.獲取內嵌樣式表和外部樣式表中CSS的值
if(document.defaultView) {
    //非IE瀏覽器
    var style = document.defaultView.getComputedStyle(div,null);
    alert(style.width);
} else if(div.currentStyle) {
    //IE瀏覽器
    alert(div.currentStyle.width);
}
相關文章
相關標籤/搜索