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

 

 

相关文章:

  • 2021-12-25
  • 2021-12-25
  • 2021-12-26
  • 2021-04-23
  • 2022-01-08
  • 2021-11-14
  • 2022-12-23
  • 2021-12-01
猜你喜欢
  • 2021-11-18
  • 2022-01-07
  • 2021-11-15
相关资源
相似解决方案