javascript 如何更改 Dropzone.js 中的缩略图 src 值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23837875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 01:39:28  来源:igfitidea点击:

How to change thumbnail src value in Dropzone.js?

javascriptjquerydropzone.js

提问by netdjw

I'm using Dropzone.js with jQuery to upload files to the server. Afer file uploaded I'm generating a "server-side" filename with the current url.

我正在使用 Dropzone.js 和 jQuery 将文件上传到服务器。Afer 文件上传我正在生成一个带有当前 url 的“服务器端”文件名。

$('.dropzone').dropzone({
    init: function() {
        this.on('success', function(file) {
            var newname = generateServersideFilename(file.name); // this is my function
            // here I need a help to find the thumbnail <img> to set the 'src' attribute
        }
    }
});

How can I find the current thumbnail imgto set the srcattribute?

如何找到当前缩略图img来设置src属性?

回答by YakirNa

This worked for me:

这对我有用:

$('.dropzone').dropzone({
    init: function() {
        this.on('success', function(file) {
            var newname = generateServersideFilename(file.name); // this is my function
            // changing src of preview element
            file.previewElement.querySelector("img").src = newname;
        }
    }
});

dropzonejshave few examples of using file.previewElement

dropzonejs有几个使用 file.previewElement 的例子

回答by yogesh singh

This can be simply be

这可以简单地是

this.on("success", function(file) {
var mydropzone = this;
mydropzone.emit("thumbnail", file, "images/x.jpg");
});

here is the linkfrom dropzone

这是dropzone的链接

回答by Ahmad Aghazadeh

this.on("addedfile", function (file) {

   file.previewElement.querySelector("img").src = "music-box-outline.svg";

});