检查列表项的数量并在条件存在时将其列化
示例页面: http://vincent-massaro.com/columns/columns.html
在此页面上,有两个有序列表,一个包含四个项目,另一个包含八个项目。我需要编写一个条件来检查每个有序列表中有多少列表项,如果超过四个,则将它们分成几列;如果少于四个,则不要分成列。现在完成此操作的代码是:
$('.mcol', this).makeacolumnlists({cols: 3, colWidth: 0, equalHeight: 'ul', startN: 1});
提前致谢!
Example page: http://vincent-massaro.com/columns/columns.html
On this page, there are two ordered lists, one with four items, and one with eight. I need to write a condition that checks how many list items are in each ordered list, and if it's more than four, split them into columns; if there are less than four, don't split into columns. The code that accomplishes this now is:
$('.mcol', this).makeacolumnlists({cols: 3, colWidth: 0, equalHeight: 'ul', startN: 1});
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一种不错的方法是使用自定义选择器。像这样的东西:
让你这样做:
Updated: As per the OP's question from the comments, here's a version of the selector for lists with between 4 and 12 items:
One nice way is with a custom selector. Something like this:
Lets you do this:
Updated: As per the OP's question from the comments, here's a version of the selector for lists with between 4 and 12 items:
使用
$('li').size() 检查 li 的数量
check the number of li's using
$('li').size()
如果想要
下的
元素的
length
属性,则需要为单独获取每个。
If you want the
length
property of<li>
elements under a<ol>
, you need to get it separately for each<ol>
.