zoukankan      html  css  js  c++  java
  • 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;
    
    }
    
  • 相关阅读:
    test
    VS dll 引用依赖
    Git配置
    编码--文字输入的前因后果
    base64相关
    异或
    UNION / UNION ALL 区别
    数据库使用规范
    chrome插件开发学习(一)
    缓存穿透 缓存雪崩 缓存并发
  • 原文地址:https://www.cnblogs.com/sntetwt/p/3894409.html
Copyright © 2011-2022 走看看