为什么显示[object HTMLImageElement]?不是<img/>?

时间:2012-05-22 13:59:45

标签: jquery xml parsing rss

我尝试从tumblr博客解析rss feed。 这是来自rss feed的xml片段。

<item>
    <title>title goes here</title>
    <description>
        <img src="http://media.tumblr.com/ajfafh.jpg"/>
        <p>text description goes here</p>
    </description>
    .
    .
</item>

我尝试使用此代码在描述标记

中获取img标记
function parse(xml){
    xml.find('item').each(function(index){
        var $item = $(this);
        var df = $item.find('description')[0].textContent;
        var $asdf = $(df).find('img').first()[0];

        var item = {
            index: index,
            description: $item.find('description')[0].textContent,
            img: $asdf
        }

        console.log(item.img);// return exactly the img tag just like what i want <img>
        // i also try this one
        console.log($(item.description).find('img').first());// return [<img src />]

        this.container.append(Mustache.to_html(this.template, item));
        //this.container = $('#container')
        //this.template = $('#template')
    });
}

我使用mustache.js将其加载到html。 HTML

<ul id="container">
    <script id="template" type="text/template">
    <li>{{img}}</li>
    </script>
</ul>

但是当我在浏览器上运行它时会返回[object HTMLImageElement],而console.log()会返回正确的值。 为什么会这样?我错过了什么?

1 个答案:

答案 0 :(得分:0)

嗯,你是log item.img,但是你试图追加item。我想你想要追加item.img