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

时间:2014-05-23 20:28:08

标签: javascript jquery dropzone.js

我使用带有jQuery的Dropzone.js将文件上传到服务器。上传文件我生成一个"服务器端"文件名与当前网址。

$('.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
        }
    }
});

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

3 个答案:

答案 0 :(得分:11)

这对我有用:

$('.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;
        }
    }
});

dropzonejs几乎没有使用file.previewElement

的示例

答案 1 :(得分:3)

这可以简单地

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

这是dropzone的link

答案 2 :(得分:1)

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

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

});
相关问题