JavaScript: The Definitive Guide, Sixth Editio javaScript权威指南(第6版) pdf 文字版-文字版, javascript电子书, 和javascript 有关的电子书:

17.3.1 Event Handler Argument

17.3.1 Event Handler Argument


Event handlers are normally (there is one exception, described below) invoked with an event object as their single argument. The properties of the event object provide details about the event. The type property, for example, specifies the type of the event that occurred. §17.1 mentioned a number of other event object properties for various event types.

In IE8 and before, event handlers registered by setting a property are not passed an event object when they are invoked. Instead, the event object is available through the global variable window.event. For portability, you can write event handlers like this, so that they use the window.event if no argument is supplied:

function handler(event) {

event = event || window.event;

// Handler code goes here

}

Event handlers registered with attachEvent() are passed an event object, but they can also use window.event.

Recall from §17.2.2 that when you register an event handler by setting an HTML attribute, the browser converts your string of JavaScript code into a function. Browsers other than IE construct a function with a single argument named event. IE constructs a function that expects no argument. If you use the identifier event in such a function, you are referring to window.event. In either case, HTML event handlers can refer to the event object as event.

欢迎转载,转载请注明来自一手册:http://yishouce.com/book/1/31457.html
友情链接It题库(ittiku.com)| 版权归yishouce.com所有| 友链等可联系 admin#yishouce.com|粤ICP备16001685号-1