Basic DOM Tutorial: event object_basic knowledge

Source: Internet
Author: User
This article mainly introduces the relevant information about the event object in the DOM basic tutorial. For more information, see the events in the browser in the form of objects, similarly, there are also differences between IE and standard dom browsers in obtaining event objects. In IE browser, the event object is a windows object attribute event. the following method is generally used for access.

The code is as follows:


OP. onclick = function (){
Var oEvent = window. event;
}

Although it is a window object attribute, the event object can only be accessed when an event occurs. after all the event processing functions are executed, the object disappears.

The standard dom specifies that the event object must be passed to the event handler as a unique parameter. An Access Event object in a browser similar to Firefox is usually used as a parameter. the code is as follows:

The code is as follows:


OP. onclick = function (oEvent ){
}

Therefore, to be compatible with the two browsers, the following methods are usually used:

The code is as follows:


OP. onclick = function (oEvent ){
If (window. event) oEvent = window. event;
}

After obtaining the Event object, the browser can process various events through a series of its properties and methods, such as mouse events, keyboard events, and browser events. And so on

The following lists common attributes and methods:

We can see from the above that there are some similarities between the two types of browsers. for example, the type attribute is compatible with various browsers. it indicates to get the event type, and the return result is similar to "click ", values such as "mousemove.

This is very useful for a function to process multiple types of events.

As follows: the same function handles multiple events.

The code is as follows:


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.