如何检测一个div的内容的高度? [英] How to detect the height of the content of a div?

查看:140
本文介绍了如何检测一个div的内容的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为DIV提供了


  • 固定高度

  • 禁用滚动功能

  • 其内容可编辑



我需要了解其内容高度是否达到或甚至超过根据用户插入的元素(文本或其他)的相同div(基于事件触发控件)。有没有人有任何简单的想法如何检测一个DIV的内容是否已经达到或甚至超过了同一个DIV的高度?

解决方案

as stian在回答中表示,可以使用jQueries height()方法来获取给定元素的高度。



然而,你会想在主div的第二个容器中使用这个方法。如此:

 < div id =myMainDivWithAHeight> 
< div id =myInnerDivExpandingWithTheContent>< / div>
< / div>

这样您就可以计算内部div的高度, ,而不是固定高度的outter div的高度。

然后,您可以比较内部和外部div高度的值。


provided a DIV with

  • fixed heigh
  • disabled scrolling feature
  • whose content is editable

I need to understand if its content height as reached or even exceeded the height of the same div according to the element (text or other) inserted by the user (control triggered on event basis). Does anybody have any simple idea how to detect if the content of a DIV has reached or even exceeded the height of the same DIV?

解决方案

As stian said in their answer, you can use jQueries height() method to obtian the height of a given element.

However, you'll want to utilise this method on a second container internal the the main div. Such that:

<div id="myMainDivWithAHeight">
     <div id="myInnerDivExpandingWithTheContent"></div>
</div>

This way you'll be calculating the height of the inner div which is expanding in relation to the content, instead of the height of the fixed-height outter div.

You can then compare the values of the inner and outter div heights.

这篇关于如何检测一个div的内容的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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