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