我正在使用本主题中的简单 rss feed 解析器示例 = Rss Parser Example .
$.get('https://stackoverflow.com/feeds/question/10943544', function (data) {
$(data).find("entry").each(function () { // or "item" or whatever suits your feed
var el = $(this);
console.log("------------------------");
console.log("title : " + el.find("title").text());
console.log("author : " + el.find("author").text());
console.log("description: " + el.find("description").text());
});
});
它很完美,但是我想在特定的 div 中显示每个输出日志,例如:
标题日志进入 <div class="Rss-Title"></div>
等等。所以最后我应该有这样的东西:
<div id="Rss">
<div class="Rss-Title"></div>
<div class="Rss-Author"></div>
<div class="Rss-Description"></div>
</div>
我的问题:做这样的事情的正确方法是什么?
最佳答案
您应该使用.html()功能
<div id="Rss">
<div class="Rss-Title"></div>
<div class="Rss-Author"></div>
<div class="Rss-Description"></div>
</div>
$.get('http://stackoverflow.com/feeds/question/10943544', function (data) {
$(data).find("entry").each(function () { // or "item" or whatever suits your feed
var el = $(this);
$('#Rss-Title').html(el.find("title").text());
$('#Rss-Author').html(el.find("author").text());
$('#Rss-Description').html(el.find("description").text());
});
});
关于jquery - 将 console.log 转换为输出到 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39488552/