javascript – 如何使用blueimp文件上传插件上传文件一次?

前端之家收集整理的这篇文章主要介绍了javascript – 如何使用blueimp文件上传插件上传文件一次?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 bluimp jQuery-File-Upload-plugin.选择一些文件上传它们没有问题,但是当我要上传另一个文件而不刷新页面时,第一个文件将再次上传.我的问题是在上传文件后如何“取消设置”文件.这是我的源代码

使用Javascript:

  1. $('#MappeFile').fileupload({
  2. dataType : 'json',autoUpload : false,maxNumberOfFiles : undefined,maxFileSize : 6000000,minFileSize : undefined,acceptFileTypes : /.+$/i,url : "/ajax/UploadFile.PHP",add : function(e,data) {
  3. $("#testUploadButton").on("click",function() {
  4. $('#progress .bar').show();
  5. if ($.browser.msie && parseInt($.browser.version,10) < 10) {
  6. $('#progress .bar').css({
  7. "background" : "url(images/progressbar.gif) no-repeat","width" : "100%"
  8. })
  9. } else {
  10. $('#progress .bar').css({
  11. 'background-color' : "#2694E8",'width' : '0%'
  12. });
  13. }
  14. data.submit();
  15. })
  16. },change : function(e,data) {
  17. $.each(data.files,function(index,file) {
  18. console.info('Selected file: ' + file.name);
  19. filesCount++;
  20. });
  21. },drop: function(e,done : function(e,data) {
  22. $.each(data.result,file) {
  23. vOutput = "<tr>";
  24. vOutput += "<td>" + file + "</td>";
  25. vOutput += "<tr>";
  26. $("#MappeFileListe").append(vOutput);
  27. filesUploaded++;
  28. if (filesCount == filesUploaded) {
  29. filesUploaded = 0;
  30. filesCount=0;
  31. $('#progress .bar').hide();
  32. }
  33. });
  34. },progressall : function(e,data) {
  35. var progress = parseInt(data.loaded / data.total * 100,10);
  36. $('#progress .bar').css('width',progress + '%');
  37. }
  38. });

HTML:

  1. <div id="KundeMappe">
  2. <form id="MappeFile">
  3. <input type="file" id="MappeFileSelect" name="files[]" data-url="ajax/UploadFile.PHP" multiple/>
  4. <div id="progress">
  5. <div class="bar" style="width: 0%;"></div>
  6. </div>
  7. <input type="button" class="neuButton" value="upload" id="testUploadButton"/>
  8. </form>
  9. <table id="MappeFileListe"></table>
  10. </div>

解决方法

我自己找到了答案 – 上传后,解除按钮的点击事件就足够了
  1. add : function(e,'width' : '0%'
  2. });
  3. }
  4. data.submit();
  5. $("#testUploadButton").off("click")
  6. })
  7. },

猜你在找的JavaScript相关文章