0

我正在尝试从 RSS Feed 中解析 publishedDate,但没有成功...

我可以使用此代码显示日期:thefeeds[i].publishedDate.. 结果是:Sat, 02 Feb 2013 22:00:00 -0800但是,我希望这更友好...

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>

    <script type="text/javascript">

        var feedcontainer=document.getElementById("feeddiv")
        var feedurl="http://feeds.folha.uol.com.br/folha/classificados/empregos/rss091.xml"
        var feedlimit=4
        var rssoutput="<ul>"
        function rssfeedsetup(){
            var feedpointer=new google.feeds.Feed(feedurl) //Google Feed API method
            feedpointer.setNumEntries(feedlimit) //Google Feed API method
            feedpointer.load(displayfeed) //Google Feed API method
        }

        function displayfeed(result){
            if (!result.error){
                var thefeeds=result.feed.entries
                for (var i=0; i<thefeeds.length; i++){

<!-- I THINK I'M DOING THIS LINES WRONG!! -->
                var pubDate = thefeeds[i].publishedDate
                var date = new Date(pubDate);
                var months = Array("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro");
                var string = date.getDate() + " " + months[date.getMonth()] + " " + date.getFullYear()

<!-- END -->

                rssoutput+="<li><span>•&lt;/span> " + string + " - <a href='" + thefeeds[i].link + "' target='_blank'>" + thefeeds[i].title + "</a></li>"
                rssoutput+="</ul>"
                feedcontainer.innerHTML=rssoutput
            }
            else
            alert("Erro ao carregar as notícias!")
        }

        window.onload=function(){
            rssfeedsetup()
        }
        </script>

怎么了?

4

1 回答 1

0

似乎缺少父代(在 for 循环中),但我不确定这是否只是复制粘贴错误。像这样,代码将循环设置i为不在数组中的数字...

 ...
 for (var i=0; i<thefeeds.length; i++)
 //--> here  is missing {
 ...
 //--> at the end of the block }
 ...
于 2013-02-27T17:57:45.937 回答