Events in jquery
1. browser-implemented event model
The implementation of DOM Level 0 event processing is to assign a handler to an element attribute, such as onclick = function (param1, param2 ){...}.
The disadvantage is that an event can only have one processing function, that is, the last processing function assigned a value. All the previous functions are overwritten.
DOM Level 2 event processing is implemented by using addEventListener (eventType, listener, useCapture)
EventType removes the "on" prefix of the previous element attribute, that is, the eventType of onclick is click.
Listener is a reference to the event processing function. The first parameter is the event object.
UseCapture refers to the use of capture or bubble to process events, generally false, that is, the use of bubble
However, IE does not implement the DOM Level 2 event processing model and does not support capturing methods, and the usage methods are different.
AttachEvent (eventName, handler)
Handler does not pass in the event object as the first parameter, but uses window. event
2. Bind events with JQuery to process elements
Bind (eventType, data, listener) bind events to JQuery objects
EventType: Event Type
Data: Object type, used in listener, can be omitted
Listener: Processing Function
You can also combine events and use namespace.
For example, click. myNamespace. In this way, several events can be processed as a unit.
EventTypeName (listener)
EventTypeName refers:
Blur
Change
Click
Dblclick
Error
Focus
Keydown
Keypress
Keyup
Load
Mousedown
Mousemove
Mouseout
Mouseover
Mouseup
Resize
Scroll
Select
Submit
Unload
Returned result package set
One (eventType, data, listener) Only executes the function bound once.
Unbind (eventType, listener) if there is no parameter, all listener will be removed
Unbind (event)
3. Event object instance
Event instance attributes
-
Altkey
-
Set to true if the Alt key was pressed when the event was triggered, false if not. The ALT key is labeled option on most Mac keyboards.
-
Ctrlkey
-
Set to true if the ctrl key was pressed when the event was triggered, false if not. data the value, if any, passed as the second parameter to the BIND () command when the handler was established.
-
Keycode
-
For keyup and keydown events, this returns the key that was pressed. note that for alphabetic characters, the uppercase version of the letter will be returned, regardless of whether the user typed an uppercase or lowercase letter. for example, both A and A will return 65. you can use shiftkey to determine which case was entered. for keypress events, use the which property, which is reliable guest SS browsers.
-
Metakey
-
Set to true if the meta key was pressed when the event was triggered, false if not the meta key is the ctrl key on PCs and the command key on Macs.
-
Pagex
-
For mouse events, specifies the horizontal coordinate of the event relative from the page origin.
-
Pagey
-
For mouse events, specifies the vertical coordinate of the event relative from the page origin.
-
Relatedtarget
-
For some mouse events, identifies the element that the cursor left or entered when the event was triggered.
-
Screenx
-
For mouse events, specifies the horizontal coordinate of the event relative from the screen origin.
-
Screeny
-
For mouse events, specifies the vertical coordinate of the event relative from the screen origin.
-
Shiftkey
-
Set to true if the Shift key was pressed when the event was triggered, false if not.
-
Target
-
Identifies the element for which the event was triggered.
-
Type
-
For all events, specifies the type of event that was triggered (for example, click). This can be useful if you're using one event handler function for multiple events.
-
Which
-
For Keyboard Events, specifies the numeric code for the key that caused the event, and for mouse events, specifies which button was pressed (1 for left, 2 for middle, 3 for right ). this shoshould be used instead of button, which can't be relied on to function consistently initialize SS browsers.
StopPropagation ()
PreventDefault ()
4. Use a script to trigger event processing
Trigger (eventType) because the Event is triggered by code, there is no Event instance or bubble
EventName ()
Blur
Click
Focus
Select
Submit
Toggle (listenerodd, listenereven)
Listenerodd 1st, 3 ...... Number of executed Functions
Listenereven 2nd, 4 ...... Number of executed Functions
Hover (overlistener, outlistener)
Blog Source:Http://www.cnblogs.com/everx/archive/2008/02/21/1076458.html