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 ); });