更新时间:2022-06-21 09:06:26
e.target
属性类型取决于你所在的元素返回 getElementById(...)
。 files
是输入的属性
元素: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement
The e.target
property type depends on the element you are returning on getElementById(...)
. files
is a property of input
element: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement
在这种情况下,TypeScript编译器不知道您正在返回输入
元素,而我们没有事件
特定于此的类。因此,您可以创建一个类似下面的代码:
In this case, the TypeScript compiler doesn't know you are returning an input
element and we dont have an Event
class specific for this. So, you can create one like the following code:
interface HTMLInputEvent extends Event {
target: HTMLInputElement & EventTarget;
}
document.getElementById("customimage").onchange = function(e?: HTMLInputEvent) {
let files: any = e.target.files[0];
//...
}