使用此代码,我得到一个列表项数组:
var column = this.children().slice(0, columnLength).remove()
我希望将它们包装在 ul 标记中,以便稍后可以像这样应用它们:
this.html(filler);
我希望这能起作用。
filler = filler.add(column.wrapAll('<ul />'))
完整代码:
jQuery.fn.splitList = function(num) {
var columnLength = Math.ceil(this.children().length/num), filler = $j();
while(this.children().length > 0){
var column = this.children().slice(0, columnLength).remove()
filler = filler.add(column.wrapAll('<ul />'))
console.log(filler);
}
this.html(filler);
};
最佳答案
这能满足您的要求吗:
filler = filler.add($("<ul></ul>").append(column));
我假设column
是LI的Array
。
关于javascript - 如何使用 jquery 将元素数组包装在元素中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26529306/