我正在尝试将图像属性附加到我的 div 图像容器中,但正如我所见,图像不在同一个容器中
<img id="imgUpload" style="width: 140px; height: 140px;" class="img-thumbnail"></img>
<img src="static/uploads/4178ba43-a9f1-4315-b8ea-88c0531cc042.png"><img id="imgUpload" style="width: 140px; height: 140px;" class="img-thumbnail"></img>
这是以下脚本。
<script>
$(function(){
$('#fileupload').fileupload({
url: 'upload',
dataType: 'json',
add: function (e, data) {
data.submit();
},
success:function(response,status) {
console.log(response.filename);
var filePath = 'static/uploads/' + response.filename;
$("#imgUpload").append($("<img>", { src: filePath }));
$('#filePath').val(filePath);
console.log('success');
},
error:function(error){
console.log(error);
}
});
})
</script>
以下 html 元素应该发挥该作用。
<div class="pull-right">
<img id="imgUpload" style="width: 140px; height: 140px;" class="img-thumbnail"/><input type="hidden" name="filePath" id="filePath"></input>
</div>
</div>
最佳答案
更改以下行
$("#imgUpload").append($("<img>", { src: filePath }));
至
$("#imgUpload").attr("src", filePath);
关于javascript - 图像属性格式不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35289877/