$.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 ); });
posted on 2017-08-08 16:16 fangfang_yu 阅读(153) 评论(0) 编辑 收藏 举报