开发者

Get image from rss feed using javascript (Feed API)

开发者 https://www.devze.com 2023-04-12 18:25 出处:网络
var entry = result.feed.entries[i]; var div = document.createElement(\"div\"); somewhere in the output of
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

精彩评论

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