Dropzone.js - maxFiles = 1不会因拖动多个文件而停止

trs*_*trs 6 javascript forms jquery dropzone.js

使用Dropzone.js,这是代码.选项"maxFiles = 1"确实会阻止在浏览时选择多个文件,但不会停止将多个文件"拖动"到dropzone区域.知道如何防止拖拽多个文件?

$(".dropzone").dropzone({
    dictDefaultMessage: "Drag image here",
    uploadMultiple: false,
    parallelUploads: 1,
    clickable: true,
    maxFiles: 1,
    url: 'somewhere' // Provide URL
});
Run Code Online (Sandbox Code Playgroud)

Abh*_*s.s 7

请添加以下代码,

init: function() {
 this.on('addedfile', function(file) {
  if (this.files.length > 1) {
   this.removeFile(this.files[0]);
  }
 });
}
Run Code Online (Sandbox Code Playgroud)


Tim*_*ss 5

为什么不使用CSS来禁用click事件.当达到最大文件时,Dropzone将自动添加一类dz-max-files-reach.

使用css禁用点击dropzone:

.dz-max-files-reached {
      pointer-events: none;
      cursor: default;
}
Run Code Online (Sandbox Code Playgroud)

我刚刚测试过,这也可以防止拖动.

信用:这个答案