javascript实现uploadify上传格式以及个数限制

前端之家收集整理的这篇文章主要介绍了javascript实现uploadify上传格式以及个数限制前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文为大家分享了javascript实现uploadify上传格式以及个数限制的关键代码,希望大家好好研究学习。

关键代码一:

var qs=$('#file_upload-queue>div');//所有的队列 var id=qs.eq(2).attr('id');//得到第三个队列的id $('#uploadTowedAccredit').uploadify('cancel',id);//这样就行了,会<a href="https://www.jb51.cc/tag/zidong/" target="_blank" class="keywords">自动</a>重置队列<a href="https://www.jb51.cc/tag/shuliang/" target="_blank" class="keywords">数量</a>和<a href="https://www.jb51.cc/tag/shanchu/" target="_blank" class="keywords">删除</a>dom对象,不能直接qs.eq(2).remove(),无效 /* if(!window.confirm("您确定<a href="https://www.jb51.cc/tag/shanchu/" target="_blank" class="keywords">删除</a>附件?")){ return; } var imgUrl=$(this).parents(".img-wrap").find("img").attr("src"); deleteImage(imgUrl); $(this).parents(".img-wrap").remove(); */

});
};

关键代码二:

拖机授权委托书:
上传附件,最多上传${towedAccreditPicMax} 张

关键代码三:

上传拖机授权委托书 function uploadTowedAccreditInit(){ $("#uploadTowedAccredit").uploadify({ 'hideButton':'true','preventCaching' : 'true','checkExisting':'true','swf': SWF,'uploader':uploadImg,'debug':false,'multi': true,'method': 'post','preventCaching' : true,'removeCompleted' : true,'removeTimeout' : 10,'requeueErrors' : true,'successTimeout' : 30,'uploadLimit' : ${towedAccreditPicMax},'fileObjName' : 'Filedata',//单张图片最大限制 'fileSizeLimit' : '1024KB','fileTypeDesc' : 'Image Files',//仅限上传jpg格式图片 'fileTypeExts' : '*.jpg;*.png','height': 24,'width':73,'buttonText' : '上传附件','auto': true,'buttonClass':'uploada btn-fff-24','onSWFReady' : function() { },'onInit':function(){ // $("#file_upload-button").css("width","100"); },//选择图片完成 'onSelect' : function() {
},//取消<a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a>
'onCancel' : function(file) {
},'onCheck': function(event,data,key) {
},//开始<a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a>
'onUploadStart' : function(file) {
  $('.uploadify-queue').html('');
},//<a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a>过程中
'onUploadProgress' : function(file,bytesUploaded,bytesTotal,totalBytesUploaded,totalBytesTotal) {
  $('.uploadify-queue').html('');
  $("#uploadTowedAccreditLinkTip").html('<em></em><a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a>中...');
},//<a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a>完成
'onUploadComplete' : function(file) {
    $('.uploadify-queue').html('');
    $("#uploadTowedAccreditLinkTip").html('<em></em><a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a>成功,待提交');
},//<a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a>成功
'onUploadSuccess' : function(file,response) {
  var obj = eval('(' + data + ')');
    var result=obj.result;
    if(result=="true"){
      var filename=obj.filename;
      $('.uploadify-queue').html('');
      $('#towedAccreditDiv').append("<div class='img-wrap'><img width='112' height='84' alt='' src='"+filename+"'><div class='mask'><em></em><span></span></div></div>");
    }
},//<a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a>失败 //附件格式不正确,请<a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a>JPG、BMP、PNG格式<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a>,大小不超过3MB
'onUploadError' : function(file,errorCode,errorMsg,errorString) {
  switch(errorCode) {
    case -100:
      alert("<a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a>的<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a><a href="https://www.jb51.cc/tag/shuliang/" target="_blank" class="keywords">数量</a>已经超出系统限制的"+$('#uploadTowedAccredit').uploadify('settings','queueSizeLimit')+"个<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a>!");
      break;
    case -110:
      alert("<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a> ["+file.name+"] 大小超出系统限制的"+$('#uploadTowedAccredit').uploadify('settings','fileSizeLimit')+"大小!");
      break;
    case -120:
      alert("<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a> ["+file.name+"] 大小异常!");
      break;
    case -130:
      alert("<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a> ["+file.name+"] 类型不正确!");
      break;
  }
},//<a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a>失败 //附件格式不正确,请<a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a>JPG、BMP、PNG格式<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a>,大小不超过3MB
'onSelectError' : function(file,errorMsg) { 
  var msgText = "<a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a>失败\n"; 
  switch (errorCode) { 
    case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED: 
      var towedAccreditDivLen = $("#towedAccreditDiv").children().length;
      msgText += "每次最多<a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a> " + $('#uploadTowedAccredit').uploadify('settings','uploadLimit') + "个<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a>"; 
      break; 
    case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT: 
      msgText += "<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a>大小超过限制( " + $('#uploadTowedAccredit').uploadify('settings','fileSizeLimit') + " )"; 
      break; 
    case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE: 
      msgText += "<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a>大小为0"; 
      break; 
    case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE: 
      msgText += "<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a>格式不正确,仅限 " + $('#uploadTowedAccredit').uploadify('settings','fileTypeExts'); 
      break; 
    default: 
      msgText += "<a href="https://www.jb51.cc/tag/cuowu/" target="_blank" class="keywords">错误</a><a href="https://www.jb51.cc/tag/daima/" target="_blank" class="keywords">代码</a>:" + errorCode + "\n" + errorMsg; 
  }
  alert(msgText);
}

});

//判断用户是否有安装flash
var obj = $("#uploadTowedAccredit").children().eq(0);
if(obj.attr('type')!= "application/x-shockwave-flash"){
alert('系统检测到您的浏览器没有安装flash插件,为了你能够正常上传图片,建议你安装flash');
return;
}

$("#uploadTowedAccredit").css("float","left");
};

javascript如何限制uploadify上传格式以及个数这个问题希望通过本文大家都应该有了一定的了解,希望可以真正帮助大家解决uploadify上传个数以及格式限制的问题。

原文链接:https://www.f2er.com/js/51564.html

猜你在找的JavaScript相关文章