jQuery将较长的ul列表分割成较小的列表 [英] jQuery split long ul list in smaller lists
本文介绍了jQuery将较长的ul列表分割成较小的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想我可以使用类似于
的东西,$ b $
$(function(){
$(ul li:nth-child(20n))。after(< / ul>< ul>);
});
但事实并非如此。任何想法如何使用jQuery的方式,使用最小的CPU?
解决方案
我会创建文件碎片与您删除 li
s,然后将它们重新安装到您想要的位置。在这种情况下,我将它们重新加入到body:
$(function(){
var $ bigList = $ ('#bigList'),group;
while((group = $ bigList.find('li:lt(20)')。remove())。length){
$('<附加(组).appendTo('body');
}
});
现场演示位于: http://jsbin.com/ejigu/33
I have a long UL list I need to break up in smaller lists containing about 20 items each.
I was thinking I could use something like
$(function() {
$("ul li:nth-child(20n)").after("</ul><ul>");
});
but that's not the case. Any idea how to use jQuery in a way that uses minimal CPU?
解决方案
I would create document fragments with your removed li
s and then reappend them to the location you want them. In this case, I reappended them to the body:
$(function(){
var $bigList = $('#bigList'), group;
while((group = $bigList.find('li:lt(20)').remove()).length){
$('<ul/>').append(group).appendTo('body');
}
});
Live Demo is at: http://jsbin.com/ejigu/33
这篇关于jQuery将较长的ul列表分割成较小的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文