我想在 id 上使用 dropzone。但是我的 Dropzone.options.myid={} 不管用。如何验证文件类型、大小
var myDropzone = new Dropzone("div#myid", { url: "/file/post"});
我无法使用标签
console.log 文件不起作用,为什么? 我的来源:
<div id="myid" style="width: 500px; height: 300px; border: 1px solid black">click here</div>
JavaScript
var myDropzone = new Dropzone("div#myid", { url: "dropzoneupload"});
Dropzone.options.myid = {
paramName: "file", // The name that will be used to transfer the file
maxFilesize: 2, // MB
accept: function(file, done) {
console.log(file);
if (file.name == "justinbieber.jpg") {
done("Naha, you don't.");
}
else { done(); }
}
};
最佳答案
我没有看到您在哪里使用 dropzone 类来定义您的 dropzone 区域,它是否会为您生成默认的 dropzone?
<div id="myDropZone" class="fallback dropzone" enctype="multipart/form-data">
<input type="file" id="files" class="display" multiple />
</div>
首先,您需要分离默认的放置区,将其添加到准备加载的文档中。
Dropzone.autoDiscover = false;
然后你jquery或者js
var $myDropZone;
$myDropZone= new Dropzone('div#myDropZone', {*all your settings*
addRemoveLinks: true, //to remove
dictRemoveFile: '<i class="fa fa-times-circle" style="font-weight: 900;
cursor:pointer;"></i>' //I used an icon and styled as button so to give a user
experience to remove it});
希望对您有所帮助,问候。
关于javascript - 使用不带表单的 dropzone.options,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52222412/