zoukankan      html  css  js  c++  java
  • js判断文件格式及大小

     

     
    //判断照片大小
    function getPhotoSize(obj){
        photoExt=obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();//获得文件后缀名
        if(photoExt!='.jpg'){
            alert("请上传后缀名为jpg的照片!");
            return false;
        }
        var fileSize = 0;
        var isIE = /msie/i.test(navigator.userAgent) && !window.opera;           
        if (isIE && !obj.files) {         
             var filePath = obj.value;           
             var fileSystem = new ActiveXObject("Scripting.FileSystemObject");  
             var file = fileSystem.GetFile (filePath);              
             fileSize = file.Size;        
        }else 
             fileSize = obj.files[0].size;    
        }
        fileSize=Math.round(fileSize/1024*100)/100; //单位为KB
        if(fileSize>=10){
            alert("照片最大尺寸为10KB,请重新上传!");
            return false;
        }
    }


    jsp页面:

    <input type="file" id="imgFile" name="upload" style="150px;" onchange="getPhotoSize(this)"/>
  • 相关阅读:
    Git学习笔记06-版本回退
    python3+selenium入门07-元素等待
    [cerc2017J]Justified Jungle
    [codeforces126B]Password
    计算几何基础模板
    floyd路径记录
    [数据结构复习]层序建立二叉树
    [patl2-011]玩转二叉树
    [poj3348]Cows
    [poj3347]Kadj Squares
  • 原文地址:https://www.cnblogs.com/xzzzys/p/7778323.html
Copyright © 2011-2022 走看看