Home >Web Front-end >JS Tutorial >How to use the Event object of JS_javascript skills

How to use the Event object of JS_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:14:251399browse

[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

Event object obtains a unified method : (from the Internet) The code is as follows:


function getEvent(event) {
var ev = event || window.event;
if (!ev) {
var c = this.getEvent.caller;
while (c) {
ev = c.arguments [0];
if (ev && (Event == ev.constructor || MouseEvent == ev.constructor)) { /Yi Fei Note: YUI source code BUG, ​​ev.constructor may also be MouseEvent, not necessarily Event
break;
}
c = c.caller;
}
}
return ev;
}


The call executes: The code is as follows:


function foo(){
var e = getEvent ();
alert(e);
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn