gpt4 book ai didi

javascript - jQuery 和 XML : Is this the last element?

转载 作者:行者123 更新时间:2023-11-30 13:22:21 26 4
gpt4 key购买 nike

我使用这段 jQuery 抓取了一些 XML 数据:

$.ajax({
type: "POST",
url: "siteList.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('wrapper').each(function(){
$(this).find('site').each(function(){
//check whether this is the last element...
});
});
}
});

我想做的是:检查我是否正在解析我拉入的 XML 中的最后一个 site 元素。

编辑:我不能(据我所知)这样做:

$(this).find('site').each(function(){
$(this).last(); //nope
$(this).find('site').last(); //nope
});

最佳答案

只需使用类似这样的方法来获取最后一个站点:

$(this).find('site').last()

希望对您有所帮助!

关于javascript - jQuery 和 XML : Is this the last element?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9789993/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com