Javascript 如何使用jquery在HTML中显示图像
我想显示存储在“AppendReturneImage(data)”函数中的图像。但我得到了错误,它无法显示图像。图像的格式应该遵循我的HTML HTML:Javascript 如何使用jquery在HTML中显示图像,javascript,jquery,html,Javascript,Jquery,Html,我想显示存储在“AppendReturneImage(data)”函数中的图像。但我得到了错误,它无法显示图像。图像的格式应该遵循我的HTML HTML: <div class="col-md-5 single-top"> <ul id="etalage"> <li> <img class="etalage_thumb_image img-responsive" src="images/si1.jp
<div class="col-md-5 single-top">
<ul id="etalage">
<li>
<img class="etalage_thumb_image img-responsive" src="images/si1.jpg" alt="" >
<img class="etalage_source_image img-responsive" src="images/s2.jpg" alt="" >
</li>
<li>
<img class="etalage_thumb_image img-responsive" src="images/si2.jpg" alt="" >
</li>
<li>
<img class="etalage_thumb_image img-responsive" src="images/si3.jpg" alt="" >
</li>
</ul>
</div>
您能否尝试创建一个
li
元素并将图像附加到它,然后将li
元素附加到您的ul
中
function appendReturnedImages(data) {
var $html = $();
$.each(data.images, function(index, element) {
$html = $html.add($("<img/>", {
height: 200,
//width: 200, // uncomment this if you need to set width as well
css: {
'max-width': 200
},
src: element
}));
$("#etalage").append($('<li/>').append($html));
});
}
您提供的代码是否不起作用?是否给出了错误?检查开发人员控制台。实际上我知道问题所在。我的appendImages函数在div中追加图像,但我必须在li中追加图像
$('#etalage').etalage({
thumb_image_width: 300,
thumb_image_height: 400,
source_image_width: 900,
source_image_height: 1200,
show_hint: true,
click_callback: function(image_anchor, instance_id){
//alert('Callback example:\nYou clicked on an image with the anchor: "'+image_anchor+'"\n(in Etalage instance: "'+instance_id+'")');
}
});
function appendReturnedImages(data) {
var $html = $();
$.each(data.images, function(index, element) {
$html = $html.add($("<img/>", {
height: 200,
//width: 200, // uncomment this if you need to set width as well
css: {
'max-width': 200
},
src: element
}));
$("#etalage").append($('<li/>').append($html));
});
}
function appendReturnedImages(data) {
var $html = $();
$.each(data.images, function(index, element) {
$html = $html.add($("<img/>", {
height: 200,
//width: 200, // uncomment this if you need to set width as well
css: {
'max-width': 200
},
src: element
}));
var $li = $('<li/>');
$li.append($html[index]);
$("#etalage").append($li);
});
}