我正在用动态内容填充一个无序列表,列表高度将填充内容,有谁知道我如何获得无序列表中前 3 个 li 标签的高度?
生成的动态内容可能如下所示,所以我只想计算前 3 个 li 标签的高度。
<ul>
<li>23 Feb 2011<br />Synergy Launch new website...<br />Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc gravida lacus a ligula dictum dignissim....</li>
<li>23 Feb 2011<br />Expat children "receive improv...<br />Expat children enjoy a better standard of education whilst living abroad compared to their home country according to the HSBC Offshore Offspring Report,...</li>
<li>25 Feb 2011<br />London Market favours Landlord...<br />The lettings market has swung dramatically in favour of landlords as an average six applicants chase every available property in London. This is a dramatic rise...</li>
<li>23 Feb 2011<br />Synergy Launch new website...<br />Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc gravida lacus a ligula dictum dignissim....</li>
</ul>
感谢您的帮助 J.
最佳答案
这为您提供了它们的所有高度...但是您可以轻松地将您想要的代码放入函数中以对每个列表项执行某些操作。
var sum = 0;
$('li:lt(3)').each(function() {
sum += $(this).height();
});
编辑:将 $('li').nextUntil(':eq(2)')
缩短为 $('li:lt(3) ')
关于javascript - jQuery 获取前 3 个 li 标签的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6138715/