Section 120th, JavaScript event object

Source: Internet
Author: User
Tags event listener

JavaScript Event Object

Learning Essentials:

1. Event Object

2. Mouse events

3. Keyboard events

4.W3C and IE

An important aspect of JavaScript events is that they have some relatively consistent features that can provide more powerful functionality for your development. The most convenient and powerful is the event object, they can help you deal with the situation of mouse events and keystrokes, in addition to modify the general event of the capture/bubbling stream function.

A. Event Object

One of the standard features of event handlers is that the event object accessed in some way contains contextual information about the current event.

Event handling consists of three parts: an object. The event handler function = function. For example, click anywhere in the document.

// Click the mouse button anywhere on the page to trigger an event function () {    alert (' Lee ');};

PS: The noun explanation of the above procedure: Click Represents an event type and clicks. The onclick represents a property of an event handler or bound object (or an event listener, listener). Document represents a bound object that is used to trigger an element area. function () Anonymous functions are functions that are executed and executed after triggering.

In addition to using anonymous functions as functions that are executed, you can also set them as separate functions.

// Click the mouse button anywhere on the page to trigger the event document.onclick = box;                        // Direct assignment of function names, without parentheses function box () {    alert (' Lee ');}

This keyword and context

In the object-oriented chapter we learned that in an object, because of the scope of the relationship, this represents the closest object to it.

// <input type= "text" value= "literal"/> function // window.onload event, wait for HTML execution to complete, execute anonymous function    var input = document.getelementsbytagname (' input ') [0];     function () {        alert (this. value);                    // Htmlinputelement,this represents the input object     };};

Section 120th, JavaScript event object

Related Article

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.