0

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>");    
        }
    });

たとえば、関数yearが2012、monthが12であると指定しましたが、fliter $( "PubYear [Year ='" + year + "']")はfind関数では機能しないようです。問題を解決する方法は?ありがとう

4

2 に答える 2

1

fliterを使用する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>");    
        }
    });
}
于 2013-01-25T06:57:18.563 に答える
1

ここで私はそれをこのように使用しました:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script>
        function get_past_issues(year, month){
            $.ajax({ 
                url: 'list.xml', 
                type:"get",
                async: false,
                success: function(xml) { 
                        $(xml).find("PubYear[Year='" + year + "']").find("PubMonth[Month='" + month + "']").each(function(){
                            console.log($(this).find('Publication').attr('ThumbnailPath'));
                         // Output is:FlippingBook/Dev/Frontend/OutPutFolder/Headline/2012/12/15/0/0/A/Content/1/Pg001.jpg
                        });
                },
                error:function(){
                    alert('err');
                }
            });
        }
        $(function(){
            get_past_issues(2012, 12);
        });
    </script>
于 2013-01-25T07:22:09.543 に答える