【问题标题】:Image attribute not properly formatted图像属性格式不正确
【发布时间】: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>

【问题讨论】:

标签: javascript jquery ajax jquery-ui dropzone.js


【解决方案1】:

更改以下行

$("#imgUpload").append($("<img>", { src: filePath }));

$("#imgUpload").attr("src", filePath);

【讨论】:

  • 非常感谢您的快速回复,代码最初位于.attr,它只显示一个缩略图。我想显示所有的拇指
【解决方案2】:

我已经回答了你之前的问题

我认为你需要这个

var img = $('<img />', { 

  src: filePath

});
img.appendTo($('.pull-right'));

【讨论】:

    【解决方案3】:

    你像这样使用 Attr $("#imgUpload").append($("&lt;img&gt;", { 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);
            }
        });
    })
    

    【讨论】:

    • 这只显示一个缩略图,我希望它显示所有上传的图像。
    • 这个“response.filename”或console.log(response.filename)是什么值;
    • dc9fe2ff-2e3c-47a7-aefd-6d72a29c3702.png files:46 success files:38 c906b428-d5a5-4bd3-9c5e-202b52449dca.png files:46 success
    • 那是在我上传了 2 张图片之后。
    • 你有 teamviwer 吗?将用户 ID 密码发送到 vadiveljobs@gmail.com 我看到代码
    猜你喜欢
    • 1970-01-01
    • 2014-11-09
    • 2010-09-28
    • 2014-04-15
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多