我有这个代码用于通过JQuery导入RSS提要。我的问题是它只导入4个RSS项目然后停止。知道为什么会这样吗?
$.fn.rssWidget = function(feedUrl, dateFormat){
var dateFormatF = dateFormat || 'day/month/year hours:minutes';
var googleFeedUrl = 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0';
var title = '<h4 class="rsswidget-feed" style="display:none;"><a href=":url">:title</a></h2>';
var item = '<hr/><h5 class="rsswidget-title" style="display:none;"><a href=":url">:title</a></h3><p class="rsswidget-date" style="display:none;">:date</p><div class="rsswidget-content">:text</div>';
$(this).each(function(){
var $that = $(this);
var feed = $(this).attr('feed') || feedUrl;
feed = encodeURIComponent(feed);
$.getJSON(googleFeedUrl
+ '&q=' + feed
+ '&callback=?'
,function(d){
var f = d.responseData.feed;
console.log(f);
$that.html(title.replace(':url', f.link).replace(':title', f.title));
$(f.entries).each(function(i,e){
var date = new Date(e.publishedDate);
var dateString = dateFormatF
.replace('day', date.getDate() < 9 ? '0' + date.getDate() : date.getDate())
.replace('month', (date.getMonth() + 1) < 9 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
.replace('year', date.getFullYear())
.replace('hours', date.getHours() < 9 ? '0' + date.getHours() : date.getHours())
.replace('minutes', date.getMinutes() < 9 ? '0' + date.getMinutes() : date.getMinutes())
;
$that.append(item
.replace(':title', e.title)
.replace(':url', e.link)
.replace(':text', e.content)
.replace(':date', dateString));
});
});
});
然后我将其放入我的HTML
<script type="text/javascript">
$(function(){
$("div#feed").rssWidget('RSS FEED URL');
});
</script>
<div id="feed"></div>