I. capture or bubble was asked yesterday: How many stages are there in the event stream? How many times have events occurred in these phases? The problem is very simple, but it is a bit messy when an event occurs several times. I always think that capture can also trigger events, and bubble can also trigger events. But the event does happen only once, capture or bubble, and I was asked yesterday: How many stages are there in the event stream? How many times have events occurred in these phases? The problem is very simple, but it is a bit messy when an event occurs several times. I always think that capturing can also trigger events, and bubbling can also trigger events. But it does happen only once! So if you write an article, you can skip it. Subquestion 1: How many stages does the event stream have? The "DOM2-level event" specifies that the event flow consists of three phases: the event capture phase, the target phase, and the event bubble phase. 1. Both IE9 and earlier ie browsers support only the last two stages, that is, they are in the target stage and event bubble stage. This order is easy to understand. Events are received on the deepest node in the hierarchy, and then spread to the parent node step by step. 2. Another event stream proposed by the early Netscape team was called event capture. That is, the top-level node should receive events earlier and gradually spread to the node with the deepest nesting level, that is, the event capture stage and the target stage. modern browsers such as chrome, ff, and IE9 support the entire three phases. Subquestion 2: How many times have an event occurred in these phases? When an event occurs, the "DOM2-level event" event stream goes through three stages (capture-> in the target-> bubble), but not events can occur at each stage. For a node, if the third parameter of the addEventListener method is true, the event occurs in the capture phase; if it is false, the event occurs in the bubble phase. So the event only happened once! If an event occurs in both the capture and bubble phases on the outer node, register the event twice. Additionally, "DOM0-level events" (elem. onclick = function (){...}) Event bubbles also exist. 2. register multiple events on the same node in the event registration sequence. Use addEventListener to add events sequentially. Use attachEvent to reverse the order of events, before registration occurs first. 3. The removeEventListener and detachEvent methods for removing events are the same callback function when an event occurs. Therefore, anonymous functions cannot be removed when an event is registered.
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