maxzonesexceeded事件未在dropzone js

时间:2017-07-15 03:19:10

标签: javascript jquery html css dropzone.js

这似乎是一个非常奇怪的问题。所有其他事件都被解雇但不是这两件事。也许maxFiles也不起作用,最终这些事件都没有解决。我做错了吗?

这是代码:

$(document).ready(function(){
  Dropzone.autoDiscover = true;
  Dropzone.options.myDropzone = {
    paramName: "file",
    maxFilesize: 5,
    maxFiles: 1,
    accept: function(file, done) {
      console.log("done");
    },
    init: function(){
      console.log(this); //WORKS
      this.on("maxfilesexceeded", function(file){
         alert("sdf"); //DOESN'T WORK
      });
      this.on("maxfilesreached", function(file){
         alert("sdf"); //DOESN'T WORK
      });
      this.on("addedfile", function(file){
        console.log("added", file); //WORKS
      });
    }
  };
});

<div class="container">
  <div class="login-form">
    <h3>Login to Conversation</h3>
    <form action="test.php" class="form-inline dropzone" id="my-dropzone" enctype="multipart/form-data">
        <input name="file" type="file" class="form-control">
  </form>
  </div>
</div>

1 个答案:

答案 0 :(得分:2)

这对我有用:

$(document).ready(function(){
    Dropzone.autoDiscover = true;
    Dropzone.options.myDropzone = {
    paramName: "file",
    maxFilesize: 5,
    maxFiles: 1,
    maxfilesexceeded: function(file) {
      console.log('exceeded')
    },
    maxfilesreached: function(file) {
      console.log('reached')
    },
    accept: function(file, done) {
      console.log("done");
    }
  };
});