如何嵌入来自Flickr的图像,以便在网站上显示图像?

时间:2014-05-11 07:00:27

标签: javascript php jquery html flickr

我想知道如何将来自FLICKR的图片嵌入到网站上,现在,我只能得到图片的网址,但我想用它来获取整个图片。这是我的代码:

<!DOCTYPE html>
<html>
<head>
  <script src="jquery-min.js" type="text/javascript"></script>

  <script type="text/javascript"> 

$(document).ready(function() {
    API_KEY = 'YOURAPIKEY'; //INSERT API KEY
    USER_ID = '28858578@N06'; //ENTER USER ID

    var photolist = [];

    $.getJSON('https://www.flickr.com/services/rest/?method=flickr.people.getPhotos&api_key=' + API_KEY + '&user_id=' + USER_ID + '&format=json&jsoncallback=?', function(rest) {

        var numPhotos = rest.photos.pages;

        for (var u =1; u < numPhotos + 1; u++) {    
            $.getJSON('https://www.flickr.com/services/rest/?method=flickr.people.getPhotos&api_key=' + API_KEY + '&user_id=' + USER_ID + '&format=json&page=' + u + '&jsoncallback=?', function(results) { var targetDiv = $('#fotolist')
                for (var m =0; m < results.photos.total; m++) {
                  targetDiv.append("https://www.flickr.com/" + 
results.photos.photo[m].owner + "/" + results.photos.photo[m].id + "<br />");
                    photolist.push("https://www.flickr.com/" + results.photos.photo[m].owner + "/" + results.photos.photo[m].id);


                }      
            });
        }    
    }); 
});
  </script>


</head>
<body>
<div id="fotolist">
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

如果photolist包含图像链接数组

var fotolist = $('#fotolist');
jQuery.each(photolist , function(index, value){
 fotolist.append('<img src="'+value+'">');
 });