<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();

 

 

相关文章: