我对事件有疑问。
我创建了两个接口:
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;
}
如何摆脱这些错误?