图像属性格式不正确
Image attribute not properly formatted
>我正在尝试将图像属性附加到我的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);
我看了你之前的问题
我认为你需要这个
var img = $('<img />', {
src: filePath
});
img.appendTo($('.pull-right'));
你这样使用 Attr $("#imgUpload").append($("<img>", { src: filePath }));
到$("#imgUpload").attr("src", filePath);
此示例
<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").attr("src", filePath);
$('#filePath').val(filePath);
console.log('success');
},
error:function(error){
console.log(error);
}
});
})
相关文章:
- 由于布尔值的变化,Django视图中的字符串格式不正确
- 输出文本不't以正确格式显示
- 文档的第一行.写的格式不正确,有时无法显示
- 格式为nnnnnnnn的字符串在电子表格中显示为日期或不正确
- 谷歌地图API'.pac项目:first'返回格式不正确
- 格式不正确的json/javascript
- 下载pdf格式不正确
- D3:“SVG4601:SVG 路径数据的格式不正确,无法完全解析
- 为什么它说输入数据数组的格式不正确 jqchart.
- 解码URI抛出错误“URI格式不正确”
- Amchart 和 Ajax 获取格式不正确的数据
- XML 解析错误:使用浏览器内置解析器解析 XML 字符串时格式不正确
- 为什么我会收到“格式不正确”错误
- 使用 jquery 访问 JSON 时格式不正确的错误
- 图像属性格式不正确
- 什么意思是“服务器标签格式不正确”,这个按钮会发生什么
- 读取具有“'”的 JSON 字符串(格式不正确?
- Javascript/JSON 错误:格式不正确
- 控制台中的 GeoJson “格式不正确”消息,并且显示为未定义
- 购物清单 Javascript 程序列表项的文本格式不正确