我想将这个AJAX调用返回的结果数量限制为5。我想我可以使用.slice()来做到这一点,但我不确定该怎么做。
$(document).ready(function() {
$.ajax({
type: "GET",
url: "myurl",
dataType: "xml",
cache: false,
success: parsePopular
});
});
function parsePopular(popular) {
$(popular).find("item").each(function() {
$("#popularArticles").append("<h1><p class='Bold'><a href='" + $(this).find("link").text() + "'>" + $(this).find("title").text() + "</a></p></h1>");
});
}
任何想法都很棒。
谢谢。
切片并移除
$(popular).find('item').slice(5).remove();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句