Home >Web Front-end >JS Tutorial >Let's talk casually about the order of events, event streams, and event triggering under javascript_javascript skills
1. First, let's understand a few concepts, "event", "event flow", "event name", "event processing function/event listening function", maybe it's a "cliché", friends who know it can skip it.
Event: An event is a specific behavior performed by the user or the browser. For example: the user clicks, which is a commonly used click event.
Event flow: Multiple events are triggered in a certain order to form an event flow.
Event name: as above. The click mentioned is the event name
The event processing function/event listening function (Dom's name) is the processing function after the event is triggered, such as obj.onclick=fn; function fn is the event processing function
2. Let’s take a look at the history. Events are part of the DOM and have been fully explained in version 3. When entering the browser except IE (which has its own event model), other browsers such as Netscape, Safari, and Opera are basically Comply with the DOM event model
3. The basic idea of bubbling events is that events are triggered sequentially from specific event targets to non-specific event targets.
First look at the following code: Code
Added html in ie6.o and above (for compatibility, avoid adding events on this tag in the end) as shown in the picture:
The bubbling event in Mozilla 1.0 is:
In fact, there is no difference in the order of the three types, but there is a difference in whether some tags support bubbling
4. Let’s look at the capture event again
IE4.0 uses bubbling events, while Netscape Navigator uses capturing events as shown below:
,
5.ie only supports bubbling events, while dom supports both "bubble events and capture events". The order is: "Capture Events"-----》》"Bubble Events", we have already I mentioned that browsers such as moz, opera, and safari basically conform to the DOM event model, so they also support "bubble events and capture events", as shown below:
6. Let’s learn how to add events to tags. The most common method is to add the following code to the tag (this kind of addition only has "capture events" in moz, which is equivalent to using addEventListener(obj,type , false) added function, we will talk about this later):
" -//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">