使用 jQuery 测量最高 UL 标签

发布于 2024-08-18 21:45:06 字数 653 浏览 4 评论 0原文

我正在尝试测量并获取最高的 ul 标签。

标记非常简单。

<ul class="ul_class">
   <li>One</li>
   <li>Two</li>
   <li>Three</li>
</ul>

<ul class="ul_class">
   <li>a</li>
   <li>b</li>
   <li>c</li>
   <li>d</li>  
   <li>e</li>
</ul>


<ul class="ul_class">
   <li>a1</li>
   <li>b1</li>
   <li>c1</li>
   <li>d1</li>  
   <li>e1</li>
   <li>f1</li>
</ul>

所以我将 ul 显示为块。显然,最高的将是带有 mosl li 标签的那个,但我怎样才能使这个高度可变呢?

感谢您提前的帮助

Im trying to measure and grab the highest of ul tags.

Markup is very simple.

<ul class="ul_class">
   <li>One</li>
   <li>Two</li>
   <li>Three</li>
</ul>

<ul class="ul_class">
   <li>a</li>
   <li>b</li>
   <li>c</li>
   <li>d</li>  
   <li>e</li>
</ul>


<ul class="ul_class">
   <li>a1</li>
   <li>b1</li>
   <li>c1</li>
   <li>d1</li>  
   <li>e1</li>
   <li>f1</li>
</ul>

So im displaying ul as blocks. Obviously the highest will te the one that has the mosl li tags in it, but how can I get this height into variable?

Thank you for your help in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

世界等同你 2024-08-25 21:45:06

您可以在每个上使用 $('selector').height() 并找到最高的

http: //docs.jquery.com/CSS/height

类似的东西

var max = 0;
$('.ul_class').each(function(){
   var h = $(this).height();
   if(h > max)
        max = h;
});

// max is the max here.

You can probably use the $('selector').height() on each one and find the tallest

http://docs.jquery.com/CSS/height

something like

var max = 0;
$('.ul_class').each(function(){
   var h = $(this).height();
   if(h > max)
        max = h;
});

// max is the max here.
甜`诱少女 2024-08-25 21:45:06

我同意 John Boker 的观点,即您需要使用 height() 而不是某种计算 li 数量的方法。这样做的原因是,根据 li 的内容,如果它是一段文本,它可能有一个 li 但比 2 个 li 列表长非常短的清单项目。

<ul>
  <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla laoreet lacinia augue, a dignissim orci sagittis nec. Fusce blandit commodo felis, et aliquam orci auctor id. Vestibulum sagittis felis non urna condimentum gravida. Duis quam erat, facilisis nec rutrum sed, hendrerit non leo. Nam varius nunc eget dolor dictum sagittis rutrum sem rhoncus.</li>
</ul>
  • Lorem ipsum dolor sat amet,consectetur adipiscing elit。 Nulla laoreet lacinia augue,一种dignissim orci sagittis nec。 Fusce blandit Commodo felis, et aliquam Orci auctor id。猫前庭矢状体非怀孕条件。 Duis quam Erat、facilisis nec rutrum sed、hendrerit 非 leo。 Nam varius nunc eget dolor dictum sagittis rut​​rum sem rhoncus。
<ul>
<li>Short</li>
<li>Short 2</li>
</ul>
  • Short
  • Short 2

假设 ul 未浮动或隐藏,John Boker 的方法将起作用。如果是这种情况,您将不得不等待隐藏或浮动它们,直到测量出它们的高度。

I agree with John Boker that you will want to use height() rather than some method that counts the number of lis. The reason for this is that depending on the contents of the li, if it were a paragraph of text, it could have one li but be longer than a 2 li list with very short list items.

<ul>
  <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla laoreet lacinia augue, a dignissim orci sagittis nec. Fusce blandit commodo felis, et aliquam orci auctor id. Vestibulum sagittis felis non urna condimentum gravida. Duis quam erat, facilisis nec rutrum sed, hendrerit non leo. Nam varius nunc eget dolor dictum sagittis rutrum sem rhoncus.</li>
</ul>
  • Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla laoreet lacinia augue, a dignissim orci sagittis nec. Fusce blandit commodo felis, et aliquam orci auctor id. Vestibulum sagittis felis non urna condimentum gravida. Duis quam erat, facilisis nec rutrum sed, hendrerit non leo. Nam varius nunc eget dolor dictum sagittis rutrum sem rhoncus.
<ul>
<li>Short</li>
<li>Short 2</li>
</ul>
  • Short
  • Short 2

Presuming that the ul is not floated or hidden, the method by John Boker will work. If that were the case, you would have to wait to hide or float them until their height has been measured.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文