您的位置:首页 > Web前端

js在前端获取在本地上传图片的尺寸

2016-07-28 17:31 429 查看
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">


程序猿必读
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: