3 回答

TA贡献1802条经验 获得超5个赞
在一种方式中,您可以替换 file = document.getElementById("fileInput").files[0];
为file = event.target.files[0]
并在 call2 中使用它,您还应该将事件传递给 call2
例如:在 html 中: <input type="file" onchange="call2(event)" />
,然后在 js 中function call2(e){let file = e.target.files[0] ... }

TA贡献1860条经验 获得超9个赞
我自己至少找到了一个更好的解决方案。虽然我不知道这是否是一个标准。
var file = document.getElementById("fileInput").files[0];
call2(file);
function call2(file) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload =async function () {
img.src= await (reader.result).toString();
console.log(await img.width);
}}
添加回答
举报