我知道每个函数都迭代一个数组.有没有办法像([i])那样访问indice?我需要能够比较当前元素的pubDate与前一个元素的pubDate,如果它是不同的输出一个新的pubdate.
$(data).find('item').each(function(i, value){
var title = $(this).find('title').text().replace(/\w+\s+\(.*?\)/, "");
var link = $(this).find('link').text();
var pubDate = $(this).find('pubDate').text();
alert(title);
alert(link);
alert(pubDate);
$('#events').append("<p>" + title + "<br/>" + link + "</p>");
});
Run Code Online (Sandbox Code Playgroud)