1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
/**
* 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);
}
|
本文转自韩立伟 51CTO博客,原文链接:http://blog.51cto.com/hanchaohan/1263861
,如需转载请自行联系原作者