When on bind, I bind the element to document and bind the parent element to the ancestor element, which causes return false to prevent bubbling from being invalid.
The on method binds events such as click on the Document object, and the click event on any element on the page bubbles to the Document object for processing.
Increased binding efficiency. When an
Block Default Events
1, in Javescript, return flase can prevent the default event, but must be added to the onmousedown incident, down to the end of the work, and then add back to Flase.
2, in the Custom function addevent, return flase will fail, please use the event object to block. Ev.preventdefault ()//block default event.
3, in the lower version of IE, the
Talking about JavaScript events, event bubbling, event capture, and blocking default events are three topics that can be difficult to avoid, whether in an interview or in a normal job.Bubble article:Let's take a look at some examples:Js: var$input = document.getElementsByTagName ("input")[0]; var$div = document.getElementsByTagName ("Div")[0]; var$body = d
+ ', ' +event.clienty);//Gets the position of the click, in pixels, the sub-notation may appear incompatible issues//Incompatible Hint: Reffereceerror event is not definedThe compatible wording is as follows:Console.log (e.clientx+ ', ' +e.clienty);/* Gets the writing of the event source (that is, the target node of the event)IE:event.srcElementFire Fox:event.tar
Event Bubbling:When an element receives an event, all it receives is propagated to its parent. Always to the top level window. This phenomenon is called the event bubbling mechanism. Out of the event trigger.Block bubbling:In the event
The interaction between JavaScript and HTML is implemented through events. The browser's event flow is a very important concept. Not to discuss those ancient browsers that have event capture and event bubbling controversy,Just know that the event flow specified in DOM2 inc
bindings for these dynamic elements as well. And then we're going to persist these processing functions and the variables we're going to use for the current context, which doesn't sound like a reliable thing.There may be other ways.Let's start with a full understanding of how events work and how they are delivered in the DOM.How the event worksWhen the user clicks on an element, an event is generated to in
The AddEventListener () method can specify the "usecapture" parameter to set the delivery event type:false→ bubble true→ captures the default false. The inner element is the p tag, the outer element is the div tag, and the experiment is as follows:In bubbling, an inner element's event is first triggered before the outer element is triggered, in order: internal ==
This article analyzes the JS bubbling event and event capture. Share to everyone for your reference, specific as follows:
Case
Summary
1. Click Mydiv. In turn, Div-body-html-document-window.
2. Click on other blank places. In turn, Html-document-window.
3. Two consecutive clicks, will be executed in order twice
4. The premise of
Bubbling events
JS "Bubbling Event" (bubble) is not a practical use of fancy techniques, it is a JS event execution sequence mechanism, "bubble algorithm" in the programming is a classic problem, bubble algorithm inside the "bubble" should be said to exchange more accurate; JS inside the "bubble
The example of this article analyzes the DOM event bubbling in jquery. Share to everyone for your reference. The specific analysis is as follows:
What is bubbling
You can have multiple events on a page, or multiple elements to respond to the same event. Suppose there are two elements on the Web page, one of which is
There are two very important features in the Javasciprt event: event bubbling and the target element.Event bubbling: When an event on an element is triggered, such as a mouse click on a button, the same event will be triggered in
e.stoppropagation () blocks event bubbling The code is as follows: ;nbsp; nbsp; return false is equivalent to calling both E.preventdefault () and E.stoppropagation () nbsp; nbsp; Return false prevents event bubbling, in addition to blocking the default behavior. If you have a jquery source code in hand, you can v
1. Block the default event for a form, or the default event "Event.preventdefault ()" That slides in the HTML5 Chinese file, blocking the default event for the element.
Demo1-1: Block element class default event
Document.getelementbytagname ("a"). AddEventListener ("click", Function (e) {e.preventdefault ()},false);
C
One, what is event bubblingFires a class of events on an object (such as clicking the OnClick event), and if this object defines a handler for this event, then this event invokes the handler, and if the event handler is not defined or the
1. Original Ecological events
Get Original event objects:
Prevent event bubbles:
1 // if the event object is provided, this is a non-IE browser 2 if (E E. stoppropagation) 3 // Therefore, it supports the W3C stoppropagation () method 4 E. stoppropagation (); 5 else6 // otherwise, we need to use IE to cancel event
ArticleDirectory
I. What is event bubbling?
Ii. What is the function of event bubbling?
3. What should I pay attention?
4. Prevent event bubbles
I. What is event bubbling
1. The event
In the browser client application platform, the basic health is event-driven, that is, an event occurs, and then the corresponding action is made.
A browser event indicates a signal that something is happening. The description of the event is not the focus of
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.