本文为大家分享了javascript实现uploadify上传格式以及个数限制的关键代码,希望大家好好研究学习。
关键代码一:
function deleteurl(){   $(body).on(click,.img-wrap .mask span,function(event){    event.stoppropagation();              var qs=$('#file_upload-queue>div');//所有的队列    var id=qs.eq(2).attr('id');//得到第三个队列的id    $('#uploadtowedaccredit').uploadify('cancel',id);//这样就行了,会自动重置队列数量和删除dom对象,不能直接qs.eq(2).remove(),无效          /*    if(!window.confirm(您确定删除附件?)){      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() {     },         //取消上传    'oncancel' : function(file) {    },    'oncheck': function(event,data,key) {    },    //开始上传    'onuploadstart' : function(file) {      $('.uploadify-queue').html('');    },         //上传过程中    'onuploadprogress' : function(file, bytesuploaded, bytestotal, totalbytesuploaded, totalbytestotal) {      $('.uploadify-queue').html('');      $(#uploadtowedaccreditlinktip).html('上传中...');    },         //上传完成    'onuploadcomplete' : function(file) {        $('.uploadify-queue').html('');        $(#uploadtowedaccreditlinktip).html('上传成功,待提交');    },         //上传成功    'onuploadsuccess' : function(file, data, response) {      var obj = eval('(' + data + ')');        var result=obj.result;        if(result==true){          var filename=obj.filename;          $('.uploadify-queue').html('');          $('#towedaccreditdiv').append(
);        }    },         //上传失败 //附件格式不正确,请上传jpg、bmp、png格式文件,大小不超过3mb    'onuploaderror' : function(file, errorcode, errormsg, errorstring) {      switch(errorcode) {        case -100:          alert(上传的文件数量已经超出系统限制的+$('#uploadtowedaccredit').uploadify('settings','queuesizelimit')+个文件!);          break;        case -110:          alert(文件 [+file.name+] 大小超出系统限制的+$('#uploadtowedaccredit').uploadify('settings','filesizelimit')+大小!);          break;        case -120:          alert(文件 [+file.name+] 大小异常!);          break;        case -130:          alert(文件 [+file.name+] 类型不正确!);          break;      }    },    //上传失败 //附件格式不正确,请上传jpg、bmp、png格式文件,大小不超过3mb    'onselecterror' : function(file, errorcode, errormsg) {       var msgtext = 上传失败\n;       switch (errorcode) {         case swfupload.queue_error.queue_limit_exceeded:           var towedaccreditdivlen = $(#towedaccreditdiv).children().length;          msgtext += 每次最多上传  + $('#uploadtowedaccredit').uploadify('settings','uploadlimit') + 个文件;           break;         case swfupload.queue_error.file_exceeds_size_limit:           msgtext += 文件大小超过限制(  + $('#uploadtowedaccredit').uploadify('settings','filesizelimit') +  );           break;         case swfupload.queue_error.zero_byte_file:           msgtext += 文件大小为0;           break;         case swfupload.queue_error.invalid_filetype:           msgtext += 文件格式不正确,仅限  + $('#uploadtowedaccredit').uploadify('settings','filetypeexts');           break;         default:           msgtext += 错误代码: + 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上传个数以及格式限制的问题。
   
 
   