我怎样才能把它变成更快的东西:
$.each(data, function(key, val)
{
rcItemsLi.eq(index++).append('<div class="rc-item-content clear hidden"><p class="rc-item-context">' + val[0] + '</p>' + val[1] + '</div>');
});
rcItemsContent = $('.rc-item-content');
在此示例中,我首先将元素附加到我想要的位置,然后使用 .rc-item-content 选择器“查找”所有元素并将它们存储在 rcItemsContent 变量中。
例如:
$.each(data, function(key, val)
{
rcItemsContent.add($('<div class="rc-item-content clear hidden"><p class="rc-item-context">' + val[0] + '</p>' + val[1] + '</div>').appendTo(rcItemsLi.eq(index++)));
});
在此示例中,我想要实现的目标(当然我没有)是添加/链接变量中的元素,并将其同时附加到我想要的位置。
最佳答案
.add
创建一个新集合。
rcItemsContent = rcItemsContent.add(...
关于jQuery 添加/链接元素到一个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14540443/