使用 jQuery 测量最高 UL 标签
我正在尝试测量并获取最高的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在每个上使用 $('selector').height() 并找到最高的
http: //docs.jquery.com/CSS/height
类似的东西
You can probably use the $('selector').height() on each one and find the tallest
http://docs.jquery.com/CSS/height
something like
我同意 John Boker 的观点,即您需要使用 height() 而不是某种计算 li 数量的方法。这样做的原因是,根据 li 的内容,如果它是一段文本,它可能有一个
li
但比 2 个li
列表长非常短的清单项目。假设
ul
未浮动或隐藏,John Boker 的方法将起作用。如果是这种情况,您将不得不等待隐藏或浮动它们,直到测量出它们的高度。I agree with John Boker that you will want to use height() rather than some method that counts the number of
li
s. The reason for this is that depending on the contents of the li, if it were a paragraph of text, it could have oneli
but be longer than a 2li
list with very short list items.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.