$.each()与$(selector).each()区别

jQuery.each( collection, callback(indexInArray, valueOfElement) )可用于迭代任何集合,无论是“名/值”对象(JavaScript对象)或数组。

   而$(selector).each()专门用来遍历一个jQuery对象

$.("li").each(function(index,elem){
    
});
复制代码
$.each( ['a','b','c'], function(index,value){
    //Index #0: a
    //Index #1: b
    //Index #2: c
    console.log( "Index #" + index + ": " + value );
});
复制代码
$.each( { name: "John", lang: "JS" }, function(index,value){
    //Index #name: John
    //Index #lang: JS
    console.log( "Index #" + index + ": " + value );
});

原文地址:https://www.cnblogs.com/fy326498/p/7307416.html