【发布时间】:2016-02-09 10:41:30
【问题描述】:
我正在尝试将图像属性附加到我的 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); -
在 img 中附加 img ???
标签: javascript jquery ajax jquery-ui dropzone.js