gpt4 book ai didi

javascript - 无法使用 javascript 和 jquery 获取 XML 属性值

转载 作者:行者123 更新时间:2023-12-02 19:03:49 25 4
gpt4 key购买 nike

XML:

<?xml version="1.0" encoding="utf-8"?>
<Publications LatestPubDate="2012-12-20" Version="0">
<PubYear Year="2012">
<PubMonth Month="12">
<Publication Name="Headline" PubDay="15" ThumbnailWidth="300" ThumbnailHeight="400" ThumbnailPath="FlippingBook/Dev/Frontend/OutPutFolder/Headline/2012/12/15/0/0/A/Content/1/Pg001.jpg" Version="0" Visible="true"/>
<Publication Name="Headline" PubDay="16" ThumbnailWidth="300" ThumbnailHeight="400" ThumbnailPath="FlippingBook/Dev/Frontend/OutPutFolder/Headline/2012/12/16/0/0/A/Content/1/Pg001.jpg" Version="0" Visible="true"/>
<Publication Name="Headline" PubDay="17" ThumbnailWidth="300" ThumbnailHeight="400" ThumbnailPath="FlippingBook/Dev/Frontend/OutPutFolder/Headline/2012/12/17/0/0/A/Content/1/Pg001.jpg" Version="0" Visible="true"/>
<Publication Name="Headline" PubDay="18" ThumbnailWidth="300" ThumbnailHeight="400" ThumbnailPath="FlippingBook/Dev/Frontend/OutPutFolder/Headline/2012/12/18/0/0/A/Content/1/Pg001.jpg" Version="0" Visible="true"/>
<Publication Name="Headline" PubDay="19" ThumbnailWidth="300" ThumbnailHeight="400" ThumbnailPath="FlippingBook/Dev/Frontend/OutPutFolder/Headline/2012/12/19/0/0/A/Content/1/Pg001.jpg" Version="0" Visible="true"/>
<Publication Name="Headline" PubDay="20" ThumbnailWidth="300" ThumbnailHeight="400" ThumbnailPath="FlippingBook/Dev/Frontend/OutPutFolder/Headline/2012/12/20/0/0/A/Content/1/Pg001.jpg" Version="0" Visible="true"/>
</PubMonth>
</PubYear>
</Publications>

js:

function get_past_issues(year,month) {  
$.ajax({ url: './demo/Headline/PublicationList.xml',
async: false,
success: function(xml) {
//$("#dialog").append("<div class = 'issues'>");
$(xml).find("Publications").find($("PubYear[Year='" + year + "']")).each(function() {
//alert ($(this).attr ('Year'));
$(xml).find("Publications").find($("PubMonth[Month='" + month + "']")).find("Publication").each(function() {
alert ($(this).attr ('ThumbnailPath'));
});
});
//$("#dialog").append("</div>");
}
});

例如,我提供了函数年份是 2012 年,月份是 12,但是过滤器 $("PubYear[Year='"+ Year + "']") 似乎不适用于查找函数?如何解决这个问题?谢谢

最佳答案

使用过滤器 find("PubYear[Year='"+ Year + "']")

function get_past_issues(year,month) {  
$.ajax({ url: './demo/Headline/PublicationList.xml',
async: false,
success: function(xml) {
//$("#dialog").append("<div class = 'issues'>");
$(xml).find("Publications").find("PubYear[Year='" + year + "']").each(function() {
//alert ($(this).attr ('Year'));
$(xml).find("Publications").find("PubMonth[Month='" + month + "']").find("Publication").each(function() {
alert ($(this).attr ('ThumbnailPath'));
});
});
//$("#dialog").append("</div>");
}
});
}

关于javascript - 无法使用 javascript 和 jquery 获取 XML 属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14516704/

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