Html:
<input type="file" id="MapUploadTd" onchange="getMapPictureSize(this.files[0])"/>Js:
var mapPictureSize = [];
function getMapPictureSize(file) {
var reader = new FileReader;
reader.onload = function (evt) {
var image = new Image();
image.onload = function () {
mapPictureSize[0] = this.width + "";
mapPictureSize[1] = this.height + "";
console.log(mapPictureSize);
};
image.src = evt.target.result;
};
reader.readAsDataURL(file);
}
这段代码展示了如何使用HTML的input[type=file]元素配合JavaScript的FileReader接口来读取用户选择的图片文件,并在图片加载完成后获取其宽度和高度,存储到mapPictureSize数组中。
426

被折叠的 条评论
为什么被折叠?



