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
How to change thumbnail src value in Dropzone.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 img
to set the src
attribute?
如何找到当前缩略图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
回答by Ahmad Aghazadeh
this.on("addedfile", function (file) {
file.previewElement.querySelector("img").src = "music-box-outline.svg";
});