为什么我的代码会在引号中返回结果?

时间:2014-06-28 17:35:08

标签: javascript html

我的代码在引号内返回所有结果。所以它看起来好像是原始的html。可以在此处找到运行代码的示例

以下是代码实际上如何从网页中显示为html的示例。

<a href="http://www.bbc.co.uk/news/world-middle-east-28069800#sa-ns_mchannel=rss&ns_source=PublicRSS20-sa">Iraq army 'moves to retake Tikrit'</a><p>Iraq's military says it has launched a major offensive to try to retake the northern city of Tikrit from Isis-led Sunni ...</p>

这是返回结果的脚本。

  

google.load(“feeds”,“1”);

function initialize() {
  var feed = new google.feeds.Feed("http://feeds.bbci.co.uk/news/rss.xml?edition=int");
  feed.setNumEntries(10);
  console.log(feed),
  feed.load(function(result) {
    if (!result.error) {
      var container = document.getElementById("feed");
      for (var i = 0; i < result.feed.entries.length; i+=1) {
        var entry = result.feed.entries[i];

        var line = '<a href="' + entry.link + '">' + entry.title + '</a>' + '<p>' + entry.contentSnippet + '</p>' ;

        var div = document.createElement("li");

       var newslist

        var newslist = div.appendChild(document.createTextNode(line));





       // var div = document.createElement("li");
       // div.appendChild(document.createTextNode(entry.contentSnippet));

        container.appendChild(div);
      }
    }
  });
}
google.setOnLoadCallback(initialize);

1 个答案:

答案 0 :(得分:3)

您正在创建文本节点,因此line即将显示为文本。

也许使用div.innerHTML=line;或使用createElement('a')createAttribute代替键入"<a ... > ... </a>"