如何捕获dropzonejs插件的事件

时间:2014-10-13 03:46:54

标签: javascript dropzone.js

我使用插件dropzonejs.com。 现在我在html文档中写这段代码

<form action="<?php print $this->link('task', 'upload'); ?>" id="pinupload" class="dropzone" style="width:450px;">
                        </form>

它完美无瑕。但我需要捕获dropzone事件:上传文件时,开始上传确认时。

我写了这段代码:

Dropzone.options.myDropzone = {
    init: function() {
      this.on("addedfile", function(file) {

       // Capture the Dropzone instance as closure.
        var _this = this;

        // Listen to the click event
        removeButton.addEventListener("click", function(e) {
          // Make sure the button click doesn't submit the form:
          e.preventDefault();
          e.stopPropagation();

          // Remove the file preview.
          _this.removeFile(file);
          // If you want to the delete the file on the server as well,
          // you can do the AJAX request here.
        });
      });
    }
  };

但是使用此代码我无法捕获事件。为什么?

1 个答案:

答案 0 :(得分:1)

对不起它的代码正常工作,只是我不专心。表格的ID应该有“myDropzone”。