日期:2014-05-18 浏览次数:20775 次
var flag=false; function sImage(ImgS){ var image=new Image(); image.src=ImgS.src; if(image.width>0 && image.height>0){ flag=true; if(image.width/image.height>= 173/173){ if(image.width>173){ ImgS.width=173; ImgS.height=(image.height*173)/image.width; }else{ ImgS.width=image.width; ImgS.height=image.height; } //ImgS.alt="实际图片大小为"+image.width+"×"+image.height; } else{ if(image.height>173){ ImgS.height=173; ImgS.width=(image.width*173)/image.height; }else{ ImgS.width=image.width; ImgS.height=image.height; } //ImgS.alt=image.width+"×"+image.height; } } }
------解决方案--------------------
<input type="file" id="fileText"> <input type="button" value="getSize" onclick="checkFileChange(document.getElementById('fileText'));"> <script type="text/javascript"> var Sys = {}; if(navigator.userAgent.indexOf("MSIE")>0) { Sys.ie=true; } if(isFirefox=navigator.userAgent.indexOf("Firefox")>0) { Sys.firefox=true; } function checkFileChange(obj) { var filesize = 0; if(Sys.firefox) { filesize = obj.files[0].fileSize; }else if(Sys.ie) { var fileobject = new ActiveXObject ("Scripting.FileSystemObject"); var file = fileobject.GetFile (document.getElementById("fileText").value); var filesize = file.Size; } alert(filesize); } </script>