将 console.log 转换为输出到 div [英] Convert console.log to output to a div
问题描述
我正在使用本主题中的简单 rss 提要解析器示例 = Rss 解析器示例.
$.get('https://stackoverflow.com/feeds/question/10943544', function (data) {$(data).find("entry").each(function () {//或item"或任何适合您的提要var el = $(this);console.log("------------------------");console.log("title :" + el.find("title").text());console.log("作者:" + el.find("作者").text());console.log("描述:" + el.find("描述").text());});});
<小时>
它很完美,但是我想在特定的 div 中显示每个输出日志,例如:
标题日志进入
等等.所以最后我应该有这样的东西:
<div class="Rss-Title"></div><div class="Rss-Author"></div><div class="Rss-Description"></div>
我的问题:做这样的事情的正确方法是什么?
你应该使用 .html()一个>函数
<div class="Rss-Title"></div><div class="Rss-Author"></div><div class="Rss-Description"></div>$.get('http://stackoverflow.com/feeds/question/10943544', 函数(数据){$(data).find("entry").each(function () {//或item"或任何适合您的提要var el = $(this);$('#Rss-Title').html(el.find("title").text());$('#Rss-Author').html(el.find("author").text());$('#Rss-Description').html(el.find("description").text());});});
I'm using simple rss feed parser example from this topic = 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());
});
});
Its perfect, however I want to show each output log in a specific div, eg:
title log goes in to a <div class="Rss-Title"></div>
and so on. So at the end I should have something like this:
<div id="Rss">
<div class="Rss-Title"></div>
<div class="Rss-Author"></div>
<div class="Rss-Description"></div>
</div>
My question: whats a proper way to do something like that?
You should use .html() function
<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());
});
});
这篇关于将 console.log 转换为输出到 div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!