将 console.log 转换为输出到 div [英] Convert console.log to output to a div

查看:69
本文介绍了将 console.log 转换为输出到 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆