js在前端獲取在本地上傳圖片的尺寸


var MyTest = document.getElementById("upload_img").files[0];
var reader = new FileReader(); reader.readAsDataURL(MyTest); reader.onload = function(theFile) {   var image = new Image(); image.src = theFile.target.result; image.onload = function() {   alert("圖片的寬度為"+this.width+",長度為"+this.height); }; };

其中,id為“upload_img”的標簽如下:

<input type="file" size="20" autocomplete="off" id="upload_img" name="Uploadfile">

 

  程序猿必讀


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM