$.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编辑  收藏  举报

导航