有谁知道为什么这里的高度可以为零?
$(document).ready(function () {
alert($("#hello").height());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img id="hello" class="browseIMG" src="https://udemy-images.udemy.com/course/750x422/64132_926c_10.jpg" />
最佳答案
这是因为即使在成功加载 DOM 之后,您甚至在从网络加载图像之前就已经获得了图像的高度。
可能你必须在图像的加载事件中这样做。
$('#hello').load(function() {
alert($("#hello").height());
});
关于javascript - div 元素的高度返回零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43274384/