我需要用链接包装此请求输出的图像,我的API知识有限,所以不幸的是我碰壁了。
这是我当前的功能,输出相册中的图像。工作版请看小提琴。
var endpoint = "https://api.flickr.com/services/rest/"
var apiKey = "e3e0e77b3f6aa14bc816b1e6855f70b7";
var photosetId = "72157682947882356";
var extras = "url_sq,url_t,url_s,url_m,url_o";
var method = "flickr.photosets.getPhotos";
var request = endpoint+"?method="+method+
"&api_key="+apiKey+
"&photoset_id="+photosetId+
"&extras="+extras+
"&format=json&jsoncallback=?";
$.getJSON(request,buildGallery);
function buildGallery(data,result){
if(result=="success"){
var photos = data.photoset.photo;
for(var i=0; i<photos.length; i++){
$('<img class="gallery_image" >').attr("src",photos[i].url_m).appendTo(".flicker");
}
}
}
https://jsfiddle.net/samwsmith/88834z4f/
谢谢你的时间。
答案 0 :(得分:0)
我设法解决了这个问题,并将此.wrap("<a href='" + photos[i].url_o + "'> </a>");
添加到我的buildGallery函数中。
var endpoint = "https://api.flickr.com/services/rest/"
var apiKey = "e3e0e77b3f6aa14bc816b1e6855f70b7";
var photosetId = "72157682947882356";
var extras = "url_sq,url_t,url_s,url_m,url_o";
var method = "flickr.photosets.getPhotos";
var request = endpoint+"?method="+method+
"&api_key="+apiKey+
"&photoset_id="+photosetId+
"&extras="+extras+
"&format=json&jsoncallback=?";
$.getJSON(request,buildGallery);
function buildGallery(data,result){
if(result=="success"){
var photos = data.photoset.photo;
for(var i=0; i<photos.length; i++){
$('<img class="gallery_image" >').attr("src",photos[i].url_m).appendTo(".flicker").wrap("<a href='" + photos[i].url_o + "'> </a>");
}
}
}
更新了小提琴:https://jsfiddle.net/samwsmith/88834z4f/ 我希望这可以帮助任何有同样问题的人。