JQUERY验证上传文件大小


function checkImgType(this_){

 

   var filepath=$(this_).val();

   var extStart=filepath.lastIndexOf(".");

 

   var ext=filepath.substring(extStart,filepath.length).toUpperCase();

 

   if(ext!=".PNG"&&ext!=".GIF"&&ext!=".JPG"){

 

  alert("图片限于png,gif,jpg格式");

  $(this_).focus();

  if ( $.browser.msie) {  //判断浏览器

    this_.select();

             document.execCommand("delete");

  }else{

$(this_).val("");

  }

  return false;

   }

 

   var file_size = 0;          

                if ( $.browser.msie) {      

                   var img=new Image();

   	img.src=filepath;   

 

if(img.fileSize > 0){

 

if(img.fileSize>3*1024){   

alert("图片不大于3MB。");

$(this_).focus();

     this_.select();

                                  document.execCommand("delete");

 return false ;

}

 

}

 

                } else {

 

                    file_size = this_.files[0].size;   

 

                    console.log(file_size/1024/1024 + " MB");     

 

var size = file_size / 1024;  

alert(size);

if(size > 3){  

alert("上传的文件大小不能超过3M!");  

$(this_).focus();

$(this_).val("");

return false ;

}

}

       return true;

}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM