JavaScript高级程序设计笔记(12)-DOM2和DOM3

计算的样式

1
2
3
4
5
6
7
8
9
10
11
12
13
var myDiv = document.getElementById('myDiv');
var computedStyle = document.defaultView.getComputedStyle(myDiv, null);

alert(computedStyle.backgroundColor);
alert(computedStyle.width);

//IE不支持getComputedStyle()方法,在IE中每个具有style属性的元素还要一个currentStyle属性。

var myDiv = document.getElementById('myDiv');
var computedStyle = myDiv.currentStyle;
alert(computedStyle.backgroundColor);
alert(computedStyle.width);