$(文件).就绪(函数(){
function getDocumentHeight() { // What's the page height? var height = $('#mainbody').height(); alert(height); ... getDocumentHeight();
jQuery为我的#mainbody div的高度保持“null”.我不明白为什么,至少应该是500px左右.
谢谢.
解决方法
如果内容正在动态加载,这些元素可能还没有高度.尝试将此代码移到页面的底部,直接在上面,看看是否解决.
更新:
尝试放置你的代码
$(window).load(function() { var height = $('#mainbody').height(); alert(height); });
在你外面
$(document).ready();