html:

<div class="field">
  <div id="file" class="dropzone">
    <div class="dz-message needsclick">
      <font><font>Drop files here or click to upload.</font></font><br>
      <span class="note needsclick">(Select the files you want to upload.)</span>
    </div>
  </div>
</div>

css:

.field{
  max-width:720px;
  margin: auto;
  margin-top:60px;
  font-size:20px;
  .dropzone{
    padding: 54px 54px;
    .dz-message{
      height:84px;
      font{
        line-height:28px;
      }
      span.note{
        height:28px;
        margin-top:28px;
        font-size:15px;
      }     }
  }
}

js:

Dropzone.autoDiscover = false;
var dropz = new Dropzone("#file", {
url: "uploadFile", //上传文件的接口
   parallelUploads:,//并行处理多少个文件上传
   uploadMultiple:true,//允许dropzone一次提交多个文件
   maxFiles: ,//最大可上传的文件个数
   maxFilesize: ,//MB
   acceptedFiles: ".csv", //可接受的文件类型
   success:function(file,data){
     // console.log(this.getAcceptedFiles().length);//获取上传的文件总数
     data=JSON.parse(data);
     if(data.code==''){
      //成功
     }else{
     }
   },
   dictMaxFilesExceeded:"文件数量过多",
   dictDefaultMessage:"Drop files here or click to upload.",
   dictFileTooBig:"可添加的最大文件大小为{{maxFilesize}}Mb,当前文件大小为{{filesize}}Mb ",
})

官网地址:http://www.dropzonejs.com/

dropzone需要注意的一点就是:

  打开文件的那一刻,就已经开始上传了。

这样的话,就会存在一个问题,一旦我们需要上传的是多个文件,而在我们选择文件的时候漏掉了文件,那么之前的文件已经上传,现在再次添加遗漏的文件,就会再次调用接口。

这样可能我们就需要一个手动上传,即:打开文件的时候,阻止自动上传,当全部的文件已经添加成功以后,再手动按上传按钮。

html:

<div class="field">
  <div id="file" class="dropzone">
    <div class="dz-message needsclick">
      <font><font>Drop files here or click to upload.</font></font><br>
      <span class="note needsclick">(Select the files you want to upload.)</span>
    </div>
  </div>
</div>
<button class="button" disabled="true">上传</button>

js:

Dropzone.autoDiscover = false;
var dropz = new Dropzone("#file", {
  url: "uploadFile",
  // addRemoveLinks: true,
  parallelUploads:,//并行处理多少个文件上传
  uploadMultiple:true,//允许dropzone一次提交多个文件
  maxFiles: ,//最大可上传的文件个数
  maxFilesize: ,//MB
  acceptedFiles: ".csv",
  autoProcessQueue: false,//阻止自动上传
  success:function(file,data){
    // console.log(this.getAcceptedFiles().length);//获取上传的文件总数
    console.log(JSON.parse(data));
    data=JSON.parse(data);
    if(data.code==''){
    }else{
    }
  },
  dictMaxFilesExceeded:"文件数量过多",
  dictDefaultMessage:"Drop files here or click to upload.",
  dictFileTooBig:"可添加的最大文件大小为{{maxFilesize}}Mb,当前文件大小为{{filesize}}Mb ", }).on('addedfile',function(file){
    $( '.button' ).removeAttr('disabled');
    $( '.button' ).bind( 'click', uploadHandle );
});
uploadHandle = function() {
  dropz.processQueue();//开启文件上传
  $( '.button' ).unbind( 'click', uploadHandle );
};

最新文章

  1. UP board 漫谈(1)——从Atom到UP Board
  2. 理解 QEMU/KVM 和 Ceph(3):存储卷挂接和设备名称
  3. H5图像遮罩-遁地龙卷风
  4. 【转】Oracle当中扫描数据的方法
  5. CentOS6.5 Openssl版本升级
  6. 《慕客网:IOS基础入门之Foundation框架初体验》学习笔记 &lt;五&gt; NSDicionary + NSMutableDictionary
  7. Get the log from android device
  8. 获取git的最后一次提交的commit id
  9. jQuery分析(3) - jQuery.fn.init
  10. iOS二进制和资源包的自检
  11. 寻找最大的k个数
  12. 推送一个已有的代码到新的 gerrit 服务器
  13. BOM(1)
  14. Unity 3D游戏开发引擎:最火的插件推荐
  15. 1、Jenkins的安装与简单配置
  16. Java获取项目根目录等其他系统属性
  17. vue Bus总线
  18. (转)Thread的中断机制(interrupt)
  19. (转载)Attempting to add QLayout &quot;&quot; to MainWindow &quot;&quot;, which already has a layout
  20. 解决gitHub下载速度慢的问题

热门文章

  1. Error: Cannot run program &quot;/home/xxx/android_developer_tools/android-ndk-r8/ndk-build.cmd&quot;: Unknown reason
  2. C#正则表达式匹配双引号
  3. Express响应方法
  4. 我们为什么要在C++中使用虚函数
  5. ROS Learning-027 (提高篇-005 A Mobile Base-03) 控制移动平台 --- Twist 消息
  6. ZROI2018提高day5t3
  7. Luogu 3466 [POI2008]KLO-Building blocks
  8. Python程序设计1——基础知识
  9. 删除GHOST中win7桌面IE删不掉的解决办法
  10. python基本概念——字符串