【问题标题】:Show file URL after upload - jQuery-File-Upload上传后显示文件 URL - jQuery-File-Upload
【发布时间】:2017-12-28 18:17:36
【问题描述】:

我尝试了很多,但没有很多关于 JS 的经验。我希望你能帮忙。

我尝试使用 Query-File-Upload (https://github.com/blueimp/jQuery-File-Upload) 并且它正在工作。我只需要一点定制。

我希望上传图片的文件 url 会在上传后显示。目前只显示预览图片,链接到文件url。

我想我找到了具体的代码,但不知道如何更改它。

on('fileuploaddone', function (e, data) {
    $.each(data.result.files, function (index, file) {
        if (file.url) {
            var link = $('<a>')
                .attr('target', '_blank')
                .prop('href', file.url);
            $(data.context.children()[index])
                .wrap(link);
        } else if (file.error) {
            var error = $('<span class="text-danger"/>').text(file.error);
            $(data.context.children()[index])
                .append('<br>')
                .append(error);
        }
    });
})

我想我需要修改 var link = $('') 之后的部分。

我希望你能帮助我。

TIA

【问题讨论】:

  • $("body").append(link); 替换$(data.context.children()[index]).wrap(link); 或在结果或状态div 中注入链接,例如$("#myDiv").append(link);
  • 很高兴它的工作:) 享受编码@user2096388

标签: javascript jquery jquery-file-upload


【解决方案1】:

$(data.context.children()[index]).wrap(link); 替换为$("body").append(link);

或者在结果或状态 div 中注入链接,例如 $("#myDiv").append(link);

【讨论】:

    猜你喜欢
    • 2014-06-01
    • 2016-06-12
    • 2014-04-20
    • 2019-11-09
    • 2020-12-08
    • 2015-09-02
    • 2012-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多