问题描述
根据用例,我如何限制 dropzone.js 允许的文件数量?
Depending on the use case, how do I constrain the number of files that dropzone.js will allow?
例如,我可能只需要允许上传 1、2 或 4 个文件.
For example, I might need to only allow 1, 2, or 4 files uploaded.
它不是uploadMultiple
.不幸的是,uploadMultiple
仅适用于每个请求处理的文件数.
It's not uploadMultiple
. Unfortunately, uploadMultiple
only applies to the number of files handled per request.
推荐答案
Nowell 指出这个问题已经解决截至 2013 年 8 月 6 日.使用此表单的工作示例可能是:
Nowell pointed it out that this has been addressed as of August 6th, 2013. A working example using this form might be:
<form class="dropzone" id="my-awesome-dropzone"></form>
你可以使用这个 JavaScript:
You could use this JavaScript:
Dropzone.options.myAwesomeDropzone = {
maxFiles: 1,
accept: function(file, done) {
console.log("uploaded");
done();
},
init: function() {
this.on("maxfilesexceeded", function(file){
alert("No more files please!");
});
}
};
dropzone 元素甚至获得了特殊的样式,因此您可以执行以下操作:
The dropzone element even gets a special style, so you can do things like:
<style>
.dz-max-files-reached {background-color: red};
</style>
这篇关于如何限制上传的 dropzone.js 文件的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!