.each()与$.each()

刚刚接触这两个方法,所以整理一下:

1.  each()可以使用jquery选择器进行遍历

$("#data_statistics_pip .none").each(function(index,item){ 
});

$("#data_statistics_pip .col-md-6").each(function (index, element) {
            var div_block = $(element).find(".pie");
            var data_block = $(element).find(".none").text()
            show_pip(div_block.attr('id'),JSON.parse( data_block))
        })

2.  $.each()不仅可以使用jquery选择器进行遍历,还可以遍历数组以及对象

使用jquery选择器进行遍历

$.each($("#data_statistics_pip .none"), function(index,item){  
})

遍历数组

$.each([ 52, 97 ], function( index, value ) {
  alert( index + ": " + value );
});

遍历对象

扫描二维码关注公众号,回复: 400124 查看本文章
var obj = {
  "flammable": "inflammable",
  "duh": "no duh"
};
$.each( obj, function( key, value ) {
  alert( key + ": " + value );
});

猜你喜欢

转载自wangsuting.iteye.com/blog/2021793