我在一个div标签中有4个img。我使用jquery ajax从数据库获取图像源,并希望将源设置为img逐个..我可以这样做...谢谢
<div class="item " style="width:450px;">
<ul class="thumbnails">
<li class="span13">
<div class="thumbnail" style="margin-left:15px;">
<img src="" alt="">
</div>
</li>
<li class="span13">
<div class="thumbnail" style="margin-left:15px;">
<img src="" alt="">
</div>
</li>
<li class="span13">
<div class="thumbnail" style="margin-left:15px;">
<img src="" alt="">
</div>
</li>
<li class="span13">
<div class="thumbnail" style="margin-left:15px;">
<img src="" alt="">
</div>
</li>
</ul>
</div>
这是从数据库中重新获取源代码的代码
$.ajax({
type: "POST",
url: "/WebServices/BannerImage.asmx/GetAllManufactureImage",
contentType: "application/json",
async: false,
success: function (data) {
$.map(data.d, function (item) {
// set the source to image
});
},
failure: function (msg) {
alert(msg);
}
});
答案 0 :(得分:0)
试试这个:
success: function (data) {
$.each(data.d, function(idx,item){
$('img').eq(idx).attr('src',item);
});
}
注意:我认为data.d是图像源。