我想读取元素的高度和宽度。
<style type="text/css">
.big {
height: 100px;
width: 100px
}
</style>
<div id="box1" style="width:50px; height=50px;"></div>
<div id="box2" class="big"></div>
对于 box01
,我可以使用 height=getElementById("box01").style.height
- 没问题。
但对于 box02 则不起作用。它什么也不返回。
最佳答案
- getComputedStyle (适用于现代浏览器)
- currentStyle (适用于旧版 IE)
关于javascript - 如何获取CSS类中元素的属性集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9500658/