javascript - 图像属性格式不正确

标签 javascript jquery ajax jquery-ui dropzone.js

我正在尝试将图像属性附加到我的 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/

相关文章:

jquery - jQuery手册中提到的 "native DOM events"是什么?

javascript - Backbone.js 全局错误处理

javascript自毁网页

javascript - 如何将背景图像定位到 html 元素的左上角和右下角?

javascript - 无法在ajax返回的代码中调用jquery函数

php - 在选择更改时更新表

javascript - 检查输入数量是否大于数据库可用数量

javascript - 哪些地方仍然需要使用 Flash?

javascript - 用小书签替换当前 URL 的结束字符

javascript - 如何让一个选择选项显示多个 div?