如何在CSS类中获取元素的属性集 [英] How to get element's attribute set in CSS class
本文介绍了如何在CSS类中获取元素的属性集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想读取元素的高度和宽度.
I want to read the element's height and width.
<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
-很好.
For box01
I can use height=getElementById("box01").style.height
- that's fine.
但是对于box02来说,它不起作用.它什么也不返回.
But for box02 it doesn't work. It returns nothing.
推荐答案
- getComputedStyle (适用于现代浏览器)
- currentStyle (适用于旧IE版本)
- getComputedStyle (for modern browsers)
- currentStyle (for old IE versions)
这篇关于如何在CSS类中获取元素的属性集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文