【问题标题】:Drop images from browser using dropzone.js使用 dropzone.js 从浏览器中删除图像
【发布时间】:2017-03-27 05:04:18
【问题描述】:

我正在制作一个网络聊天应用程序,该应用程序具有拖放文件然后将其上传到服务器的功能(我必须使它像具有此功能的 whatsapp web 一样)。我正在使用 dropzone.js 来实现这一点,并且到目前为止一直工作得很好,除了一件事。从浏览器删除图像时,永远不会调用事件“发送”。 这是示例

new Dropzone('.drag-overlay', { 
  url: "www.example.com",
  paramName: "attachment",
  init: function() {
    this.on("drop", function(e){
      console.log("Drop event");
    });
    this.on("sending", function(file){
      console.log("Sending event");  
    });
  }
});

drop 事件可以正常调用,但发送永远不会被调用。谁能告诉我如何使用这个库从另一个浏览器发送文件?

谢谢

【问题讨论】:

    标签: javascript drag-and-drop dropzone.js


    【解决方案1】:

    发送事件调用。上传任何文件。更改 Call Dropzone 方法。

    var myDropzone = new Dropzone
    

    现场演示 Here .在网页中查看控制台

    见下例

    // Dropzone class:
    var myDropzone = new Dropzone(".drag-overlay", { 
      url: "www.example.com",
      paramName: "attachment",
      init: function() {
       this.on("drop", function(e){
       alert('Drop event');
       console.log("Drop event");
       });
      this.on("sending", function(file){
      alert('sending event');
      console.log("Sending event");  
      
    });
    /*This Code Only Remove tooltip error*/
    this.on('error', function(file, errorMessage) {
      var mypreview = document.getElementsByClassName('dz-error');
      mypreview = mypreview[mypreview.length - 1];
      mypreview.classList.toggle('dz-error');
      mypreview.classList.toggle('dz-success');
    });
      }
      
      });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.3.0/dropzone.css" rel="stylesheet"/>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.3.0/basic.css" rel="stylesheet"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.3.0/dropzone.js"></script>
    <div class="clsbox-1" runat="server"  >
    		<div class="dropzone drag-overlay" id="drag-overlay">
    
    		</div>
    	</div>

    【讨论】:

    • 很抱歉,在你的小提琴中,当我从浏览器中删除图像时,发送事件仍然没有被触发。你能详细说明你的答案吗?
    • 我认为这里有一个误解,我看到了您更新的答案,您添加了一个警报,以便更容易找出事件是否被触发。为了清楚起见,我所说的“从浏览器中删除图像”的意思是,假设您在另一个选项卡上打开谷歌搜索图像,然后从结果中拖动图像并将其拖放到 jsFiddle 中的放置区域
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-14
    • 2010-11-19
    • 2011-02-18
    • 2015-04-12
    • 1970-01-01
    相关资源
    最近更新 更多