Why is there a parameter (EV) inside the JS event function?

Source: Internet
Author: User

Because EV is the parameter of the event! The EV contains the parameters of the event trigger, such as the EV with the Click event. E.pagex,e.pagey, KeyDown event contains Ev.keycode, etc., in IE, Ev is the global can be obtained through window.event, in other browsers are passed as parameters.
So many of the event functions are written like this:
Mydiv.onclick = function (EV) {
if (!ev) {ev = window.event;}//This sentence can also be written as: ev=window.event| | Ev
Alert (ev.pagex+ "," +ev.pagey);
}

When will JS use var oevent=ev| | The event?????

var oevent=ev| | Event

This sentence is written to be compatible with each browser,

In the Firefox browser, the event-bound function gets to the event itself and needs to be passed in from the function, while browsers such as IE can use event or window.event to get the events themselves.

The purpose of this sentence: it is necessary to obtain information about the event and to use it. Such as:

    1. Get keys pressed or bounced by the keyboard

    2. Gets the position coordinates of the mouse

    3. Get the elements of a departure change event

    4. Get Event name

    5. Get the current propagation phase of an event

    6. Gets the date time that the event was generated

As for the above how to obtain, you can fill in the JS event related functions and properties.

Example:

<div id= "dd" > </div>

O=document.getelementbyid ("DD");

O.onclick=function (EV) {

var oevent=ev| | Event

alert (Oevent.screenx);

}

Why is there a parameter (EV) inside the JS event function?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.