【发布时间】:2011-10-24 23:17:23
【问题描述】:
我正在使用 JQuery 的 $.getJSON 函数来下载一些图像的 url,我试图将它们输出到一个 div 中。我试图让输出看起来像这样:
<a href="the image url (shot.short_url)"><img src="the direct image url (shot.image_teaser_url)" /></a>
但是,它输出的是这个:
<div id="body-wrapper">
<a href="http://drbl.in/300896">[object Object]</a>
<a href="http://drbl.in/298080">[object Object]</a>
<a href="http://drbl.in/290395">[object Object]</a>
<a href="http://drbl.in/290324">[object Object]</a>
<a href="http://drbl.in/268595">[object Object]</a>
<a href="http://drbl.in/265197">[object Object]</a>
<a href="http://drbl.in/256368">[object Object]</a>
<a href="http://drbl.in/252519">[object Object]</a>
<a href="http://drbl.in/242235">[object Object]</a>
<a href="http://drbl.in/241676">[object Object]</a>
</div>
请你告诉我在输出图像的情况下我哪里出错了?
这是我的代码:
function work() {
$('#body-wrapper').empty();
$.getJSON("http://dribbble.com/jakekrehel/shots.json?callback=?", function(data){
$.each(data.shots, function(i,shot){
var image = $('<img/>').attr('src', shot.image_teaser_url);
var title = '<a href=\"' + shot.short_url + '\">';
var string = title;
string = string + image;
string = string + '</a>';
$('#body-wrapper').append(string);
});
});
}
【问题讨论】:
-
这是一个对象而不是字符串。取消对 url 值的引用。
-
谢谢,我现在用
var image = '<img src=\"' + shot.image_teaser_url + '\" />';。
标签: javascript jquery html json