做了个小实例,对比各种高度 html代码:
<button type="button" id="mybtn1">$(window).height()</button>
<button type="button" id="mybtn2">$(document).height()</button>
<button type="button" id="mybtn3">$(document.body).height()</button>
js代码:
$(function(){
//打印$(window).height()的值
$("#mybtn1").on("click",function(event){
console.log("$(window).height():"+$(window).height());
});
//打印$(document).height()的值
$(document).on("click","#mybtn2",function(event){
console.log("$(document).height():"+$(document).height());
});
$("#mybtn3").on("click",function(event){
console.log("$(document.body).height():"+$(document.body).height());
});
});
$(window).height(); //浏览器当前窗口可视区域高度
$(document).height(); //浏览器当前窗口文档的高度
$(document.body).height(); //浏览器当前窗口文档body的高度,内容越多,body高度越高,出现滚动条,数值会很大.