5

I can't figure out if this is possible, basically want to run an each function on every article and run another each function inside that each function on every li in that article, is this possible? I can post more details later.

4

2 回答 2

7

jQuery $.each() 函数只是一个循环。它遍历选择器返回的项目。既然是这种情况,如果您选择页面上的每个 UL,那么在查看该 UL 项目时,您选择该 UL 的所有 li 项目,然后以此类推,每个 li 中的所有跨度。如果物品在那里,你可以永远继续下去。没关系,这只是一个循环。

 $.each("ul", function(index, element)
 {
      var $this = $(this);
      var $items = $this.find("li");
      //now next loop
      $.each($items, function(n, e)
      {
          //this is each li in this ul
      });
 });
于 2013-10-21T18:18:36.250 回答
6

像这样:

jQuery.each([[1,2], [3,4], [5,6]], function(index, value) {
  jQuery.each(value, function(subindex, subvalue) {
    console.log(subvalue);
  });
});

输出:

1
2
3
4
5
6
于 2013-10-21T18:07:14.883 回答