我只想显示一篇文章,但是当我将(0,2)更改为(0,1)时,没有任何内容出现。有快速解决方案吗?
YUI().use('yql', function(Y){
var query = 'select * from rss(0,2) where url = "http://rss.cnn.com/rss/money_latest.rss"'
var q = Y.YQL(query, function(r){
//r now contains the result of the YQL Query as a JSON
var feedmarkup = '<div>'
var feed = r.query.results.item // get feed as array of entries
for (var i=0; i<feed.length; i++){
feedmarkup += '<p><a href="' + feed[i].link + '">'
feedmarkup += feed[i].title + '</a></p>'
feedmarkup += '<p>' + feed[i].description + '</p>'
feedmarkup += '<p><a href="' + feed[i].link + '">'
feedmarkup += '<span class="more">Read more</span>' + '</a></p>'
}
document.getElementById('uknews').innerHTML = feedmarkup
})
})
&#13;
<script src="http://yui.yahooapis.com/3.18.1/build/yui/yui-min.js"></script>
<div id="uknews"></div>
&#13;
答案 0 :(得分:0)
我找到了答案并希望这有助于其他人:
YUI().use('yql', function(Y) {
var query = 'select * from rss(0,1) where url = "http://rss.cnn.com/rss/cnn_world.rss"'
var q = Y.YQL(query, function(r) {
//r now contains the result of the YQL Query as a JSON
var feedmarkup = '<div class="news-feed">'
var feed = r.query.count > 1 ? r.query.results.item : [r.query.results.item]; // get feed as array of entries
for (var i = 0; i < feed.length; i++) {
feedmarkup += '<div class="feed-title"><a href="' + feed[i].link + '">'
feedmarkup += feed[i].title + '</a></div>'
feedmarkup += '<div class="feed-description">' + feed[i].description + '</div>'
feedmarkup += '<div class="feed-link"><a href="' + feed[i].link + '">'
feedmarkup += '<span class="more">Learn more</span>' + '</a></p>'
}
document.getElementById('uknews').innerHTML = feedmarkup
})
})
.feedflare {
display: none;
}
div.feed-description {
display: block;
max-width: 400px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="http://yui.yahooapis.com/3.18.1/build/yui/yui-min.js"></script>
<div id="uknews"></div>