用jquery如何实现数据的定量抽取以及分配?


   
  如下的代码,如果写成循环?因为现在是写死的,当$(".new_lovephoto > li")个数后,如何实现?
  
//假定$(".new_lovephoto > li")有54个,在里面按顺序抽取16个
var num = $(".new_lovephoto > li");
for(var i = 0; i<num.length; i++){
var td_num1 = num.slice(16,32);
var td_num2 = num.slice(32,48);
var td_num3 = num.slice(48,54);
}
//创建一个li,里面每个li放16个
var td_chang1 = "<li><div class='contain'><ul class='new_lovephoto'></ul></div></li>"
var td_chang2 = "<li><div class='contain'><ul class='new_lovephoto'></ul></div></li>"
var td_chang3 = "<li><div class='contain'><ul class='new_lovephoto'></ul></div></li>"
$("#album_list > li").last().after(td_chang1);
$("#album_list > li").last().after(td_chang2);
$("#album_list > li").last().after(td_chang3);
td_num1.appendTo($(".new_lovephoto").eq(1))
td_num2.appendTo($(".new_lovephoto").eq(2))
td_num3.appendTo($(".new_lovephoto").eq(3))

jquery JavaScript

xxy1333 12 years, 9 months ago
   
  var num = $(".new_lovephoto > li");
  
var space = 16;
for(var i = 0; i<num.length; i+=space){
$("#album_list > li").last().after("<li><div class='contain'><ul class='new_lovephoto'>"+mum.slice(i,(i+space)).join('')+"</ul></div></li>");
}

2318751 answered 12 years, 9 months ago

Your Answer