我试图通过

var high = document.getElementById("hintdiv").style.height;

alert(high);

摆脱一个div框高度值,如果属性包含div标签里我能得到这个值就好了,但它返回如果属性为空值在css部分中定义。

这很好,它显示100px为一个值。该值可以被访问。

.

.

var high = document.getElementById("hintdiv").style.height;

alert(high);

这不好,它显示一个空的警报屏幕。该值实际上是0。

#hintdiv

{

height:100px

display: none;

}

.

.

var high = document.getElementById("hintdiv").style.height;

alert(high);

但是我没有问题访问/改变“显示:无”属性是否是在该标签或在CSS部分。 div框通过属性定义方法(标签内或CSS部分)正确显示。

我也试图通过其他的变化来访问值,但没有运气

document.getElementById("hintdiv").style.height.value ----> undefined

document.getElementById("hintdiv").height ---->undefined

document.getElementById("hintdiv").height.value ----> error, no execution

任何解决方案?

TIA。

2010-06-16

Jamex

+4

请参阅http://stackoverflow.com/questions/1098349/reading-non-inline-css-style-info-from-javascript和http://stackoverflow.com/questions/1048336/cant-access-css- selectors-properties-from-javascript –

2010-06-16 01:51:50

+0

另请参阅:http://gist.github.com/369133和http://stackoverflow.com/questions/2531737/javascript-incapable-of-getting-elements-max-height-via -element-style-maxheight/ –

2010-06-16 02:14:42

+0

谢谢大家,这当然是意想不到的。我想我会为这个1(或2个元素)做内联样式。 –

2010-06-16 02:26:27

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐