Cancel Default Action
The method of the consortium is E.preventdefault (), ie is using E.returnvalue = false;
In browsers that support AddEventListener (), you can also cancel the default action for the time by calling the Preventdefault () method of the time object. However, in IE prior to IE9, you can achieve the same effect by setting the ReturnValue property of the event object to False. The following code assumes an
This article mainly introduces JavaScript and jquery mouse mouse event bubbling, this article summarizes some of the findings of the mouse event, and gives the JavaScript and jquery test code, the need for friends can refer to the
Simple Mouse Movement Events:
Enter
The code is as follows:
MouseEnter: Not bubbling
1. What is bubblingeg"http://www.w3.org/1999/xhtml">"Content-type"Content="text/html; Charset=utf-8"/> "content">Outer DIV Element"msg">When you click the ' inner span element ', which triggers the Click event of the ThatThe inner span element is clickedThe outer div element is clickedThe BODY element is clickedThis is caused by event bubbling.2. Issues caused by
JQuery blocks event bubbling instance code. jquery blocks bubble instances.
JQuery prevents event bubbling instance code:The definition of event bubbling is not described here. For details, refer to the section about jquery
Sometimes we don't want bubbles or default events to happen, so it takes some jquery methods to block bubbles and default events. There are three ways to prevent different levels of blocking. A:return false--->inEventHandler, preventsdefaultBehavior andEventbubbing. return falsein the handling of events, you can block the default events and bubbling events. B:Event. Preventdefault ()---> InEventHandler, preventdefault
/a >1.event.stoppropagation ();Event bubbling is blocked during event processing, but the default behavior is not blocked (it performs a hyperlink jump)2.return false;Event bubbling is blocked during event processing, and the defa
However, in today's large web interaction projects, such as large webgame projects, the JavaScript event bubbling effect is worth paying attention to. This article is a simple example of JavaScript event bubbling and usage considerations.
If you're not impressed by the JavaScript
(1) What is event foamingfirst of all, you have to understand that when an event occurs, the event always has an event source, that is, the object that raised the event, an event cannot be generated out of thin air, this is the oc
1, event bubbling
When you click on the internal
Event bubbling can cause unexpected effects, and sometimes it is necessary to block the bubbling behavior of the event, using the Stoppropagation () method to implem
A:return False--->in event handler, prevents default behavior and event bubbing.return false in the handling of events, you can block default events and bubbling events.B:event.preventdefault ()---> in event handler, prevent default event (allows
Preventdefault:Preventdefault It is a method of event object that cancels the default behavior of a target element. Since the default behavior is, of course, the element must have the default behavior to be canceled, and if the element itself has no default behavior, the invocation will of course be invalid. What elements have default behavior? such as link As we all know, the default action of link Suppose there is a link var a = document.getElementB
Ubb
Event bubbling (incident float mechanism)OK, let me call it the event bubbling. Originally Ralf published in his blog on the As2.0 use event bubbling method. It's a creative idea.Event bub
Event bubbling and default behaviorWhen an Event triggers an event on the DOM, an Event object is generated, this object contains all Event-related information (resulting in Event eleme
1. What is event bubbling trigger a certain type of event on an object (such as clicking an onclick event)? If this object defines the event handler, this event will call this handler. If this handler is not defined or the
As shown, the gray block contains a red block, assuming we have a click-to-box event for each of the gray and red blocks, and when we click on the red block, we do not want to trigger the gray block of the bounding box event, which requires blocking the bubbling event.The block bubbling
This article was initially published in Http://szhshp.orgReprint Please specify
Event snapping and bubblingThe first catch is necessarily the parent node, then a layer of layers is captured down, then a layer of layers bubbles upHere is a TD to be clicked onThrough three stages:
Capture phase: From parent node, gradually bubbles to the target node, that is, from top to bottom
Close to the target elem phase (this phase activates both
1. Event bubbling:When you click inside the Event bubbling can cause unintended effects, and sometimes it is necessary to block the bubbling behavior of events, using the Stoppropagation () method.Modify the Click event function of the Bind the Click
The problem with JavaScript programming is that when you add an event to HTML, it triggers the event that you don't want to trigger because the browser defaults to the bubbling event trigger mechanism. The following function can be used to solve the problem. [Compatible with IE and FF]1. Block
Click event bubbling block in JSAnalytical:A div layer ' out ' containing a div layer ' in '. As follows:Two layers are bound to click events, but when you click on the in layer, the Click event will appear bubbling, but also trigger the out layer of click events.But you don't want to trigger an out click
Original address: http://missra.com/article/web-57.htmlNested tag elements that, if both parent and child elements are bound to events, may trigger the event of a parent element when the inner child element is clicked, and the JavaScript block default event and JavaScript block event Bubbling example are described belo
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.