javascript - 如何使用 jquery 将元素数组包装在元素中?

标签 javascript jquery

使用此代码,我得到一个列表项数组:

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/

相关文章:

javascript - 通过动态生成的href标签调用javascript函数(js函数只有一个参数)

javascript - 创建在单击另一个对象时隐藏的跨度

javascript - 匿名关闭和全局进口

javascript - 文件读取永远不会完成

javascript - 当页面刷新时,AngularJS 到底会发生什么?

javascript - 将 Vue 组件暴露给外部项目

jquery - 使用 Visual Studio Intellisense 构建 jQuery 选择器字符串

javascript - 通过 ASPX 响应写入 JSON 时的 IE 错误

ruby-on-rails - Rails 可以让 Ajax 保持开放多长时间

javascript - 从动态生成的下拉选项中选择值