jQuery $(window).height()返回文档高度 [英] jquery $(window).height() is returning the document height

查看:205
本文介绍了jQuery $(window).height()返回文档高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定我正在犯一个简单的错误,但我只是在警告$(window).height(),它返回的值与$(document).height()相同.

I'm sure there is a simple error I'm making, but I am simply alerting $(window).height() and it returns the same value as $(document).height().

我正在使用13英寸的MBA,浏览器的窗口高度在780px-820px(大约)之间达到最大值时,但每次返回的窗口高度都与文档高度相同.在每种情况下,我都在网站上工作超过1000像素.

I am on a 13" MBA and my window height of my browsers when maximised between 780px - 820px (roughly) but each time it returns a window height identical to that of document height. In every case on the site I am working on it is over 1000px.

这是怎么回事?

alert($(window).height());
alert($(document).height()); 

推荐答案

在没有doctype标签的情况下,Chrome会为两个调用报告相同的值.

With no doctype tag, Chrome reports the same value for both calls.

添加像<!DOCTYPE html>这样的严格doctype会使这些值按所宣传的那样工作.

Adding a strict doctype like <!DOCTYPE html> causes the values to work as advertised.

doctype标记必须是文档中的非常第一件事.例如,即使它没有呈现任何内容,您也不能在其之前输入任何文本.

The doctype tag must be the very first thing in your document. E.g., you can't have any text before it, even if it doesn't render anything.

这篇关于jQuery $(window).height()返回文档高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆