简体   繁体   English

如何使用javascript获取元素的高度,包括填充和边框

[英]how to get the height of a element including padding and borders using javascript

i would like to know how to get the height of a element including padding and borders using javascript so ill know the actually height the element has when rendered in a browser. 我想知道如何使用javascript获取元素的高度,包括填充和边框,因此我不知道该元素在浏览器中呈现时的实际高度。 Can anyone help me please and im still new to javascript 谁能帮助我,我对javascript还是陌生的

You're looking for element.offsetHeight and element.offsetWidth . 您正在寻找element.offsetHeightelement.offsetWidth

According to quirksmode.com , these properties work in all of the major browsers. 根据quirksmode.com ,这些属性可在所有主要浏览器中使用。 Hooray! 万岁!

Using jQuery, you can get element height including padding with $(ele).outerHeight() , get element height including padding, border and margin by $(ele).outerHeight(true) . 使用jQuery,您可以通过$(ele).outerHeight()获得包含填充的元素高度,通过$(ele).outerHeight(true)获得包含填充,边框和边距的元素高度。

see also https://api.jquery.com/outerHeight/ 另请参阅https://api.jquery.com/outerHeight/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM