[04]JS获取文件大小方法

  1. </pre><pre name="code" class="html"><input id="file" type="file">  
  2. <input id="Button1" type="button" value="button" onclick="check()">  
  3. <script>  
  4. window.check=function(){  
  5. var input = document.getElementById("file");  
  6. if(input.files){  
  7.                 //读取图片数据  
  8.   var f = input.files[0];  
  9.   var reader = new FileReader();  
  10.   reader.onload = function (e) {  
  11.       var data = e.target.result;  
  12.       //加载图片获取图片真实宽度和高度  
  13.       var image = new Image();  
  14.       image.onload=function(){  
  15.           var width = image.width;  
  16.           var height = image.height;  
  17.           alert(width+'======'+height+"====="+f.size);  
  18.       };  
  19.       image.src= data;  
  20.   };  
  21.       reader.readAsDataURL(f);  
  22.   }else{  
  23.       var image = new Image();   
  24.       image.onload =function(){  
  25.           var width = image.width;  
  26.           var height = image.height;  
  27.           var fileSize = image.fileSize;  
  28.           alert(width+'======'+height+"====="+fileSize);  
  29.       }  
  30.       image.src = input.value;  
  31.   }  
  32. }  
  33. </script>  

 转载 :http://blog.csdn.net/u014236259/article/details/52885591

原文地址:https://www.cnblogs.com/yeziTesting/p/7691148.html