1
我遇到事件問題。TypeScript中未定義的屬性
我有兩個接口創建:
export interface IEEvent extends JQueryEventObject, MSEventObj {
preventDefault:() => void;
cancelBubble: bool;
}
export interface IEElement extends HTMLElement {
click: (event?: IEEvent) => void;
onmousedown: (event?: IEEvent) => void;
onmousemove: (event?: IEEvent) => void;
onmouseup: (event?: IEEvent) => void;
}
我嘗試設置onmousedown\move\up
道具和我得到一個錯誤......
public static StopPropagation(element: HTMLElement): void {
(<IEElement> element).onmousedown = StopPropagationHandler; // error here
(<IEElement> element).click = StopPropagationHandler; // error here
(<IEElement> element).onmouseup = StopPropagationHandler; // error here
}
private static StopPropagationHandler(e?: IEEvent): void {
if (typeof (e) === "undefined") {
e = <IEEvent> window.event;
}
if (typeof (e.preventDefault()) !== "undefined") { // error here
e.preventDefault(); // error here
}
e.cancelBubble = true;
}
如何擺脫這些錯誤?
你在哪裏調用'StopPropagation'功能?我認爲你的問題確實存在,因爲你沒有傳遞有效的元素。 – Fenton