jQuery $("body").height()返回未定义 [英] jQuery $("body").height() returns undefined
本文介绍了jQuery $("body").height()返回未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的电话
$("#ContextMenuModal").height($("body").height());
但是$("body").height()
在Firebug中查看时返回未定义.
However $("body").height()
returns undefined when I view it in Firebug.
什么会导致jQuery返回未定义的车身高度?
What would cause jQuery to return undefined for the body height?
我正在使用jQuery 1.4.1.
I am using jQuery 1.4.1.
这是在iFrame中
推荐答案
只需使用
$(document).height() // - $('body').offset().top
和/或
$(window).height()
代替$('body').height()
instead $('body').height()
要扩展一点,
$(window).height(); // returns height of browser viewport
$(document).height(); // returns height of HTML document
正如bažmegakapa指出的那样,尽管有几个像素,但还是有细微的差别.可以通过从文档高度中减去主体偏移量来计算主体的真实高度(如上文所述):
As bažmegakapa points out, there is a slight difference, albeit a few pixels. The true height of the body can be calculated by subtracting the body offset from the document height (like I mentioned above):
$(document).height() - $('body').offset().top
这篇关于jQuery $("body").height()返回未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文