开发者

Get image from rss feed using javascript (Feed API)

var entry = result.feed.entries[i];
var div = document.createElement("div");

somewhere in the output of

div.appendChild(document.createTextNode(entry.content));

there are several

<img s开发者_Python百科rc="http://ww... is there a simple way just to get image url? Maybe something with .match?


here's the way i did it..

var findImg = entry.content;
var img = $(findImg).find('img').eq(0).attr('src'); //i use jquery to find 1st img src

function imgFeed(){
    var defaultImg= "images/default.jpg"; 
    if(img==null){
        return defaultImg;  // if cant find any, show default image src
    }else{
        return img;
    }
}
yourElement.append('<img width="194" height="91" src="'+imgFeed()+'" alt="#" />');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜