首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dropzone.js和remove按钮

Dropzone.js和remove按钮
EN

Stack Overflow用户
提问于 2014-04-11 00:42:23
回答 1查看 13.7K关注 0票数 1

我利用dropzone.js实现了文件上传功能。我像这样创建表单:

代码语言:javascript
复制
<form action="/target-url" id="my-dropzone" class="dropzone"></form>

<script>
  // myDropzone is the configuration for the element that has an id attribute
  // with the value my-dropzone (or myDropzone)
  Dropzone.options.myDropzone = {
    init: function() {
      this.on("addedfile", function(file) {

        // Create the remove button
        var removeButton = Dropzone.createElement("<button>Remove file</button>");


        // 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.
        });

        // Add the button to the file preview element.
        file.previewElement.appendChild(removeButton);
      });
    }
  };
</script>

我已经在html文件头中添加了dropzone.js文件。但是,当我将一个文件拖入框中时,我得到了以下错误:

代码语言:javascript
复制
Uncaught ReferenceError: Dropzone is not defined

请帮个忙。

EN

回答 1

Stack Overflow用户

发布于 2014-06-18 18:30:05

例如,您可以使用非常简单的代码

代码语言:javascript
复制
myDropzone.on("addedfile", function(file) {
  file.previewElement.addEventListener("click", function() { myDropzone.removeFile(file); });
});
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22994031

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档