如何使用jQuery从div中仅获得3行

问题描述 投票:1回答:1

我有一个div,我给了它一些特定的line-heightwidth

我在下面放置了代码

document.getElementById("content").onload = countLines();
function countLines() {
   var el = document.getElementById('content');
   var divHeight = el.offsetHeight
   var lineHeight = parseInt(el.style.lineHeight);
   var lines = divHeight / lineHeight;
   console.log("Lines: " + lines);
}
<div id="content" style="width: 80px; line-height: 20px">
hello how are you? hello how are you? hello how are you? hello how are you?
</div>

但是我只想显示该div中的3行,并删除该div中的所有其他生命,而这3个数字是动态变化的,我想用jquery删除所有其他行。

有人可以帮我吗?>

我有一个div,我给了它一些特定的行高和宽度。我将代码放在document.getElementById(“ content”)。onload = countLines();下。函数countLines(){var el = ...

javascript html
1个回答
2
投票

您可以为元素设置overflowmax-height css属性,如下所示:

© www.soinside.com 2019 - 2024. All rights reserved.