[
{
"link" : "images/examples/image-3.png",
"image" : "images/examples/image-3.png",
"title" : "copy"
},
{
"link" : "images/examples/image-3.png",
"video" : "video placeholder",
"title" : "copy"
}
]
在这个例子中,我想要一个条件,如果这个值是“视频”,那么如果值是“图像”就这样做……但我似乎无法获得“视频”或“图像”的句柄”。
这是我的功能:
$.getJSON("javascripts/media.json", function(data) {
$("<ul class='gallery'></ul>").prependTo("#content");
for (var i=0; i<data.length; i++) {
var gallery = data[i];
//alert(data[1]);
if (gallery.image = true) {
$(
"<li class='image'>" +
"<a class=\"imageLink\" href='" + gallery.link + "' rel=\"lightbox[gallery]\">" +
"<img src=" + gallery.image + " alt=" + gallery.title + ">" +
"</a>"
+ "</li>").appendTo(".gallery");
}
else if (gallery.video = true) {
$(
"<li class='video'>" +
"<a class=\"videoLink\" href='" + gallery.link + "' rel=\"lightbox[gallery]\">" +
"<img src=" + gallery.video + " alt=" + gallery.title + ">" +
"</a>"
+ "</li>").appendTo(".gallery");
}
}
}).error(function() { alert("error"); });