jquery获取高度错误(可以获取到宽度,但获取不到高度),及解决办法

<div   class="foo">
	<div style="display: none;">
	3333333
	</div>
</div>

 

jquery获取一个元素的高度,但元素的子元素设置display:none;

<script type="text/javascript">

alert($('.foo').height());
alert($('.foo').width());
</script>

或设置了$('.foo').hide();

$('.foo').height()将获取不到高度。

解决办法是在获取高度前显示,获取后隐藏

$('.foo').show();
$height=$('.foo').height();
$('.foo').hide();

 

 

posted on 2014-03-14 10:20  左小兵  阅读(1752)  评论(0编辑  收藏  举报

导航