Jquery note events

Source: Internet
Author: User

Browser model:
1. DOM 0th-level model
The event handler declares the attribute assigned to the DOM element through the reference of the bar function instance. This is also our most common, such as onclick.
Copy codeThe Code is as follows:

$ ("Img"). onmouseover = function () {alert ("hello ");}

(1) Event instances and Event bubbles are the most interesting ones.
Event instances are used by most browsers to pass the event class instance as the first parameter to the function, but in ie, the Event is specified to the window attribute. in obtaining the target element, the w3c standard browser has a target, ie takes the srcElement attribute and writes it as a compatibility event as follows:
Copy codeThe Code is as follows:
$ ("Img"). onclick = function (event ){
If (! Event) event = window. event;
Var target = event.tar get? Event.tar get: event. srcElement;
}

(2) event bubbling
The target element gets the opportunity for a difficult event. The event model sticks to the parent element of the target element to see if a handler is created for the same type. If yes, the handler is also called until the top of the DOM tree
For w3c standard browsers, The stopPropagation () of event can be used. For ie, the cancelBubble of event can be used to cancel bubbling.

2. 2nd-level model
Only one handler defect can be registered for each attribute storage event in the 0-level model.
Copy codeThe Code is as follows:
$ ("Img"). addEventListener ('click', function1, false). addEventListener ('click', function2, false );

In a level-2 model, an event is triggered. First, the event is first propagated from the DOM tree to the target element (capture phase), and then bubbles up, if the third parameter of addEventListener is false, a bubble processing program is created. If the parameter is true, a capture processing program is created.
This is also the first time I heard about the capturing model. ie6 and 7 do not support the 2nd-level model, so it is no wonder that some ie browsers support attachEvent (eventName, handler) similar to the bubble model ).

Then we solve this problem for jquery's bind...
See jquery practices

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.