zoukankan      html  css  js  c++  java
  • js和jQuery前台校验文件大小

    1、支持Google 不支持IE

    <script type="text/javascript"
     src="${pageContext.request.contextPath}/foundation/common/js/jquery-1.11.1.min.js">
    </script>
    <script type="text/javascript"
     src="${pageContext.request.contextPath}/foundation/common/js/jquery-1.11.1.js">
    </script>

    function uploadF(){
        var idCardOrPhotoFile=$("#idCardOrPhotoFile").val();
        var iopStr=idCardOrPhotoFile.substr(idCardOrPhotoFile.lastIndexOf( ".")).toUpperCase();
         var ff = $(":file");
         if(iopStr!= ".JPG"){
          alert("身份证头像图片类型只能是.jpg类型,请重新上传!");
        ff.after(ff.clone().val(""));
        ff.remove();
          return false;
         }
       var files = $('input[name="idCardOrPhotoFile"]').prop('files');//获取到文件列表
         alert("1");
       var _file = files[0];
       alert("2");
       alert(_file.size);
       if(!_file){
        return ;}
       if(_file.size>60*1024){
        alert("身份证头像图片不能超过60KB");
        ff.after(ff.clone().val(""));
        ff.remove();
        return false;
       }
      }

     <input type="file" style=" 300px"
                 name="idCardOrPhotoFile" id="idCardOrPhotoFile" onchange="uploadF()"/>

  • 相关阅读:
    窗口看门狗(WWDG):神舟IV实验
    RTC实验:神舟IV
    C语言运算符优先级
    PWM输出:神舟IV验证
    独立看门狗(IWDG):神舟IV实验
    ADC 转换:神舟IV实验
    输入捕获模式简介
    输入捕获:神舟IV实验
    #ifndef 百度百科
    DAC:神舟IV实验
  • 原文地址:https://www.cnblogs.com/Defry/p/4554947.html
Copyright © 2011-2022 走看看