【问题标题】:View in HTML instead of console.log在 HTML 而不是 console.log 中查看
【发布时间】:2015-01-01 09:53:43
【问题描述】:

我想在我的 HTML 页面而不是 console.log 中显示语句的结果

我是新手:)

这是JS:

  $.ajax({
      url: 'xml/articles.json',
      dataType: 'json',
      type: 'get',
      cache: false,

      success: function(data) {

          $(data.builds).each(function(index, value){

        console.log(value.number);
          });
      }
  });

这是我的 HTML 页面:

<!DOCTYPE html>
<html>

    <head>

        <title> JSON RSS parser </title>

    </head>

    <body>

        <div class="feed">

        <ul> </ul>

    </div>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script type="text/javascript" src="js/logic.js"></script>

    </body>

</html>

我试过了,但没有用:

        $('.feed ul').append(
        $('<li />', {
            text: number
        })
        );
    });
},

有什么想法吗?

【问题讨论】:

    标签: javascript jquery html json rss


    【解决方案1】:

    尝试创建节点并附加它们。

    var ul = document.querySelector('div.feed > ul');
    
    $(data.builds).each(function(index, value){
    
      var li = document.createElement('li');
      var text = document.createTextNode(value.number);
      li.appendChild(text);
      ul.appendChild(li);
    });
    

    【讨论】:

    • 你知道是否可以将 URL 更改为服务器链接吗?
    猜你喜欢
    • 2014-08-27
    • 1970-01-01
    • 2017-10-23
    • 1970-01-01
    • 2020-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    相关资源
    最近更新 更多