计算段落相对于其中内容[数据]的高度(字符数)

calculate height of paragraph with respect to content [data] in it (number of characters)

本文关键字:高度 字符 数据 相对于 段落 计算      更新时间:2023-09-26

段落具有固定宽度的300px

font-size:20px;
line-height:1.4`
overflow:hidden

我想知道将要占用的总高度按UI中的段落从我们拥有的数据(number of characterfont-sizeline-heightwidth:300px

您可以根据自己的要求使用ineerHeight或高度

$('p').innerHeight();
$('p').height();

使用.height()

$(document).ready(function(){
alert("height  => " + $("p").height());
 alert("innerHeight => " + $('p').innerHeight());
})
p{
  font-size:20px;
line-height:1.4`;
overflow:hidden;
  width:300px;
    background-color:red;
  padding:5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>ABC  xyz ABC XYZ ABC XYZ ABC  xyz ABC XYZ ABC XYZ</p>