可能重复:
why jquery .height() get a different result on chrome?
我有一个<div>
与CSS类myclass
。 CSS类如下:
.myclass {
position: absolute;
width: 192px;
font-size: 11px;
background-color: #FFF;
padding: 15px 15px 0;
box-shadow: 0 1px 3px rgba(34, 25, 25, 0.4);
-moz-box-shadow: 0 1px 3px rgba(34, 25, 25, 0.4);
-webkit-box-shadow: 0 1px 3px rgba(34, 25, 25, 0.4);
display: block;
}
它没有指定高度。内容由PHP动态加载。在jQuery的$(document).ready(function() { });
,我调试的div的高度:
console.log($('div.myclass').height()); // the result = 330
HTML:
<div class="myclass">
<img src="image.png" />
<p>Text here text here</p>
</div>
但是,如果我用Inspect Element
功能在谷歌浏览器,它显示531px。为什么有差异?我怎样才能得到531px
的价值?
UPDATE:$(this).outerHeight(); // 345px, as there is 15px margin
已经在'$(document).ready(function(){});' – Raptor
@ShivanRaptor加载窗口没有准备好文档。 – undefined
这个工程! '$(window).load'时,'$(this).outerHeight();'值是准确的。但为什么'$(document).ready'不起作用? – Raptor