jquery-遍历each

使用案例一

    $.ajax({
        url : webPath + "/clickCount",
        type : "POST",
        dataType : "json",
        data : {
            ids : ids
        },
        success : function(data) {
            var arr = data.list;
            $.each(arr, function(i, value) {
                for (var j = 0; j < news.length; j++) {
                    if (news[j].idStr == arr[i].newsID) {
                        $("#" + arr[i].newsID + "count").text(
                                arr[i].totalCommentCount);
                        $("#" + arr[i].newsID + "clickCount").text(
                                arr[i].weekClickCount);
                    }
                }
            });
        }
    });

 

$("button").click(function(){
  $("li").each(function(){
    alert($(this).text())
  });
});

each() 方法规定为每个匹配元素规定运行的函数。

提示:返回 false 可用于及早停止循环。

function(index,element)

必需。为每个匹配元素规定运行的函数。

  • index - 选择器的 index 位置
  • element - 当前的元素(也可使用 "this" 选择器)

 

posted @ 2015-10-21 13:27  243573295  阅读(188)  评论(0)    收藏  举报