为什么这样写大部分时候获取到的都是是0呢 只有个别的图片能输出宽度 这是为什么?var upload = document.getElementById('upload');
upload.onchange=function(){ var file = this.files[0]; if (file) { var reader = new FileReader();
reader.onload = function (event) { var txt = event.target.result; var img = document.createElement("img");
img.src = txt; console.log(img.width); document.getElementById("result").appendChild(img);
};
}
reader.readAsDataURL(file);
}
1 回答
达令说
TA贡献1821条经验 获得超6个赞
var upload = document.getElementById('upload'); upload.onchange=function(){ var file = this.files[0]; if (file) { var reader = new FileReader(); reader.onload = function (event) { var txt = event.target.result; var img = document.createElement("img"); img.src = txt; img.onload = function () { console.log(img.width); document.getElementById("result").appendChild(img); } }; } reader.readAsDataURL(file); }
添加回答
举报
0/150
提交
取消