Javascript 获取元素的全高?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3410765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 04:31:29  来源:igfitidea点击:

Get full height of element?

javascriptjquery

提问by matt

My blog has a content divwith an idof #content. When I select it, e.g. with Firebug it outlines the full height of the div, with all its padding and margins at the top and the bottom.

我的博客内容divid#content。当我选择它时,例如使用 Firebug,它会勾勒出 的全部高度,div以及顶部和底部的所有填充和边距。

jQuery height()returns only the inner height of the element itself.

jQueryheight()只返回元素本身的内部高度。

How can I query the fullheight of the element? If there are other elements with a lot padding and margin in them I want all of itadded up and as one value.

如何查询元素的高?如果还有其他元素有很多填充和边距,我希望将所有元素加起来并作为一个值。

Which method should i use?

我应该使用哪种方法?

回答by tausun

You can use outerWidthand outerHeightfunctions available after jQuery >= 1.3.

您可以使用outerWidthouterHeight可用的功能后jQuery >= 1.3.

$(elemenet).outerHeight()will return height including height with borders and paddings

$(elemenet).outerHeight()将返回高度,包括带有边框和填充的高度

use $(element).outerHeight(true)to include margins as well.

也用于$(element).outerHeight(true)包含边距。