获取 div 的真实高度 (Jquery)



我想知道div的真实高度。

如果我要求$var.height()他只是告诉我修复CSS高度。

我怎样才能获得div 的实际高度而不是固定的 css 高度。

你有没有试过 outerHeight((,也许这会对你有所帮助,试试这个

$(document).ready(function() {
  $("button").click(function() {
    alert("Outer height of div: " + $("div").outerHeight());
  });
});
div {
  height: 100px;
  width: 300px;
  padding: 10px;
  margin: 3px;
  border: 1px solid blue;
  background-color: lightblue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div></div><br>
<button>Display the outer height of div</button>
<p>outerHeight() - returns the outer height of an element (includes padding and border).</p>

jquery具有outerHeight()函数。

http://api.jquery.com/outerheight/

获取当前计算的外部高度(包括填充、边框和可选的边距(

最新更新