樣式
1.訪問元素樣式
var div = document.getElementById('div1');
div.style.height //獲取高度
2.DOM樣式屬性和方法
cssText //css代碼
length
parentRule
getPropertyCSSValue(propertyName) //獲取特定屬性的CSSVALUE對象
getPropertyPriority(propertyName) //給定屬性使用了!important設置,則返回'important',不然返回null
getPropertyValue(propertyName) //返回給定屬性的字符串值
item(index)
removeProperty(propertyName)
setProperty(propertyName,value,priority)
//遍歷
var prop,value,i,len;
for(I=0;i<myDiv.style.length;i++){
prop = myDiv.style[I] //myDiv.style.item(i)也行
value = myDiv.style.getPropertyValue(prop);
alert(prop+' : '+value);
}
5.計算樣式
//內聯(lián)和外部樣式綜合計算后的結果
car computedStyle = document.defaultView.getComputedStyle(myDiv,null);