我有这个样本:
link
代码 HTML:
<div class="dropzone dz-clickable" id="myDrop">
<div class="dz-default dz-message" data-dz-message="">
<span>Upload or drag patient photo here</span>
</div>
</div>
代码 JS:
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("div#myDrop", {
addRemoveLinks: true,
url: "#",
maxFiles: 1,
init: function() {
this.on("maxfilesexceeded", function(file) {
alert("You are not allowed to chose more than 1 file!");
this.removeFile(file);
});
this.on("addedfile", function(file) {
myDropzone.options.removefile.call(myDropzone, mockFile);
// I want to delete an existing element
});
}
});
var fileName = $('#profilePicture').val();
var mockFile = {
name: fileName,
size: 12345
};
myDropzone.options.addedfile.call(myDropzone, mockFile);
myDropzone.options.thumbnail.call(myDropzone, mockFile, "https://lh3.googleusercontent.com/-eubcS91wUNg/AAAAAAAAAAI/AAAAAAAAAL0/iE1Hduvbbqc/photo.jpg?sz=104");
我想要做的是当用户上传文件时,然后删除现有的文件。
你怎么能正确地做到这一点?
提前致谢!
最佳答案
试试这个方法。
removedfile: function(file) {
file.previewElement.remove();
}