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);
}}
添加回答
舉報