Nested DIV elements, if the parent and child elements are bound to a number of events, then click on the most inner child elements may trigger the parent element of the event, the following describes the JS block default events and JS block event Bubbling example, please refer to the use of it1. Event.preventdefault (); --Block The default
JQuery prevents event bubbling code instances, and jquery bubbling
JQuery blocks event bubbling code instances:This topic describes a code example. This code can be used to implement the time bubble function and can be used for reference.The Code is as follows:
The above
and bubbling:Window.onload=function () {var Ohd=document.getelementbyid ("HD");//Buttons abovevar Oul=document.getelementbyid ("list");//The following listvar ali=document.getelementsbytagname (' Li ');var bok=true; Give a switch, now the state is turned onOhd.onclick=function (EV) {var oev=ev| | EventOev.cancelbubble=true;if (BOK) {oul.style.display= ' block ';} Click the first time displayElse{oul.style.display= ' None ';} Click Hide AgainBok=!bok; Click once to reverse}for (Var i=0;iAli[i].o
and Konqueror support. And the older opera and icab don't support either.
Iii. Captured Events
When you are using a Catch type event
Copy Code code as follows:
| |
---------------| |-----------------
| element1 | | |
| -----------| |----------- |
| |element2 \/| |
| ------------------------- |
| Event Capturing |
------------------
Compatible with the JavaScript blocking event bubbling code of various browsers, and javascript bubbling
Here is just a simple code demo, because the time issue has not been studied in depth, because the content that blocks event bubbles is used in today's project, so I found a lot to find a usable one, special record.
can terminate the other when either party occurs. If you want to stop event propagation and the default operation at the same time, you can return false in the event handler, which is a shorthand for calling. Stoppropagation () and. Preventdefault () at the same time on the event object.Detailed description of event
1. Event Delegation: The method of handling dynamic element event binding with event bubbling.DivID= ' Parent '> Divclass= ' child '>Div> Divclass= ' child '>Div> Divclass= ' child '>Div> Div>If you are binding dynamic events to a div of class child, using bubbling is the most efficient:functio
Note: The source of this article is translatable webEvent bubbling is a term you encounter while learning JavaScript, which involves invoking the order of event processing when one element is nested by another, and two elements registering the same event (for example, a click event).But
What is an event?Events are specific moments of interaction that occur in a document and in a browser window. The event is the heart of the JavaScript app beating, and the glue that sticks everything together, and when we interact with the Web page in the browser for some type of interaction, the event occurs.An event
capture events at different levels of the object layer.
"Centralized Processing example"
Copy Code code as follows:
(2) Let different objects capture the same event at the same time, and call their own proprietary handler to do their own thing, just like the boss orders, their employees to do their job.
"Capturing the same event exampl
The bubbling event and capture event in JS:Bubbling event: The bubbling event is triggered from the inside out, that is, all ancestor elements that reach the page from the beginning of the bound element, are called
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
1. IE only bubbles. W3c first captures and then bubbles. In view of my understanding of the difficult process of event bubbling and capture (after reading several blog posts, I guess this problem is not very difficult ~ Later I found that it is not. It is difficult to apply it to advanced functions.) I want to write this article light enough for beginners to understand. To facilitate the test (... SyntaxHig
JS Event bubbling
JS So-called event bubbling is a child element of an event is triggered, its ancestor element of the event is also recursive execution
Html:
Js:
$ ("ul[data-type= ' Citypick ']"). On (' click ', function ()
The first conclusion: there are two ways of executing in the event execution flow. One is event bubbling (that is, the order in which events are executed is performed from bottom to top); The other is capture (that is, the order in which the events are executed is performed from the top down);Block event
Talk about JavaScript events, event bubbling, event capture, and blocking default events These three topics, whether in the interview or in peacetime work, are difficult to avoid.
Event Capture Phase: an event is searched down from the top level of the tag until the
1 function () {}, Usecapture:false);-------------->outer-------------->innerThe default is no capture. ----------> by inward and outward------------->inner------------->outerdiffers from Xmlhttp.send ("GET", url, async:true);---------> Indicates whether async asyncEvent capturing in JavaScript--------------> from inside Out, event Bubblin----------> by inward and outward
First put the code, you create an arbitrary HTML file, such as a.html, and then put this piece of code in.Open with Chrome browser and review the elements, the final interface is as follows:This gives two layers, one id=father, the outermost layer, and the other Id=son the innermost layer.By the way, the browser's event delivery type is briefly described.Microsoft and early Netscape used event
The order in which events occur
Suppose another element is nested within one element and both have an OnClick event handler function (event handler). If the user clicks Element 2, the click events for element 1 and element 2 are triggered. But which event was triggered first? Which event handler function will be execu
1. Event bubblingMicrosoft has proposed an event flow called event bubbling. Event bubbling can be figuratively likened to putting a stone into the water, and bubbles will come up from the bottom. That is, the
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.