使用案例一
$.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) | 必需。为每个匹配元素规定运行的函数。
|
本文详细介绍使用jQuery的AJAX方法进行数据请求,并通过DOM操作更新页面内容的实践案例。包括如何发送POST请求获取JSON数据,以及遍历DOM元素并显示其文本。

786

被折叠的 条评论
为什么被折叠?



