2012-07-11 65 views

回答

0

添加jQuery庫本,並嘗試

<script type="text/javascript"> 
function Size() { 
    if ($.browser.msie) { 
    var a = document.getElementById('file').value; 
     $('#myImage').attr('src',a); 
     var imgbytes = document.getElementById('Image').fileSize; 
     var imgkbytes = Math.round(parseInt(imgbytes)/1024); 
     alert(imgkbytes+' KB'); 
    }else { 
     var fileInput = $("#file")[0]; 
     var imgbytes = fileInput.files[0].fileSize; // Size returned in bytes. 
     var imgkbytes = Math.round(parseInt(imgbytes)/1024); 
       alert(imgkbytes+' KB'); 
    } 
    }  
    </script> 

    <img id="Image" src="" style="display:none;"><br> 
    <button onclick="Size();">Image Size</button> 
    <input type="file" id="file" /> 
    <input type="button" value="find size" onclick="Size()" />