What is the blocking event bubbling method in jquery? This article has prepared two ways to prevent event bubbling, the difference between the two ways. Return false not only prevents the event from bubbling up, but also prevents
1, by returning false to cancel the default behavior and prevent the event from bubbling.
JQuery Code:
$ ("form"). Bind (
"submit",
function () {return
false;
}
);
2. By using the Preventdefault () method, only the default behavior is canceled.
JQuery Code:
$ ("form"). Bind (
"submit",
function (event) {
event.preventdefault ();
}
Click a box to pop up, but sometimes you don't want to operate it. You just want to click a blank space to hide the box. The following is a specific implementation:Most of the time, we have such a small function when doing front-end operations. Click a box to pop up. However, if you don't want to operate it, you just want to click a blank space to hide the box. In the following scenario, click a small button to bring up a modal box. This is simple, but we want to hide the modal box when you clic
. First, we have to block bubbling. Otherwise, clicking the button actually triggers the above two events, modal cannot be displayed, but it is actually popped up and hidden immediately. Besides, when we have many widgets in the modal box, it is difficult to judge the clicks in the modal box.
Here, I think there is one of the most classic methods, which is simple but clever,
First, listen to an event for
The JS bubbling mechanism means that if an element defines event A, such as the Click event, if the event is triggered and the bubbling event is not blocked, then the event propagates t
function Stopbubble (e) {Commonly used on mouse or keyboard eventsif (e e.stoppropagation) {The consortium cancels bubbling eventsE.stoppropagation ();}else{IE Cancel bubbling EventWindow.event.cancelBubble = true;}};
1, cancelbubble (HTML DOM Event object property): If the event handle wants to prevent an
When using the JS event, the outer element event may be triggered by an event in the inner element, such as clicking on the outer layer of the inner element and triggering a click, which is called event bubbling.$ ( Document). Ready (function(e) { $ ("#wai"). Click (funct
Thanks for browsing, welcome to Exchange =. =
Company development Web pages need to use pop-up windows, the use of Jquery-ui custom download still need more than 150 KB, want some luxury (finally down only 11kb, compression 2kb, ah, my God),Mobile phone side pop-up windows and PC side somewhat different, and the phone has a pop-up window rolling with the parent page scrolling interaction problems,So decided to write a plug-in, specifically against the mobile phone page pop-up window.The Ma
In front-end development, due to browser compatibility and other issues, we often use "Stop event bubbling" and "Block browser default behavior ". 1. Stop event bubbling JavascriptCode // If the event object is provided, this is a non-IE browserIf (E E. stoppropagation)/
Simple Mouse Movement Events:
Enter
Copy Code code as follows:
MouseEnter: Not bubbling
MouseOver: Bubbling
The MouseOver event is triggered regardless of whether the mouse pointer crosses the selected element or its child elementsThe MouseEnter event is triggered only when the mouse pointer
Simple Mouse Movement Events:EnterMouseEnter: No bubbling mouseover: Bubbles trigger The MouseOver event whenever the mouse pointer crosses the selected element or its child elements the MouseEnter event is triggered only when the mouse pointer passes through the selected elementMove outMouseLeave: No bubbling mouseout
Example of JavaScript blocking event bubbling, javascript example
Previously, I encountered an event bubble problem and went to the Internet to search for it. Most of the results were the same code, and the post was not very smooth. When FF is involved, you can use e. stopPropagation ();. Somehow I did not succeed. However, I found that FF supports e. cancelBubbl
Http://www.aspxhome.com/javascript/skills/200712/262128.htm
That is to say, the mouse event that uses the DIV to frame the flash div is not passed to the body.
Record the methods mentioned in this Article /*---------------------------Function: Stop event bubbling.---------------------------*/ Function Stopbubble (E) { // If an
1. Block event bubbling, making it a catch-type event trigger mechanism.1 functionstopbubble (e) {2 //If an event object is provided, this is a non-IE browser3 if(e e.stoppropagation)4 //so it supports the Stoppropagation () method5 e.stoppropagation ();6 Else7 //Otherwise, we need to use IE to cancel the
This is a basic article. It uses JavaScript to observe the event bubbling mechanism in the Dom and describes how to block default behavior and how to organize event bubbling.
1. The first example can be run in Firefox.
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
Co
Description: Prevents events from bubbling onto the DOM tree, which is the event handler on any predecessor element that is not triggered.
Version added:1.0
Event.stoppropagation ()
We can use event.ispropagationstopped () to determine whether this method has been invoked (on that event object).
This method is also valid for trigger ()-defined events.
Note tha
I learned an event bubbling mechanism today and thought it was a bit problematic. I tested it myself and shared the results with you, which helps you better understand the event bubbling mechanism.
For example:
After you click "hello", f1 will pop up, and f2 f3 will pop up. Then, when the sub-tag generat
JQuery. Event provides a very simple method to prevent event bubbles: Event. stopPropagation (); The code is as follows:Copy code $ ("P"). click (function (event ){Event. stopPropagation (); // do something}) However, this method does not work for events bound
(' on ' + evname, function () {Fn.call (obj);});}}Bind (document, ' click ', fn1);# # # Two different ways to bindMeans of canceling bubbling: Event.cancelbubble = true; (deprecated)Event.stoppropagation ();The first type: Default bubbling,The first: Only one homogeneous event can be bound on an element, and if you continue to bind, the second
1. Event target the event object is now stored in the event handler for the variable event. The Event.target property holds the target element where the event occurred. This attribute is specified in the DOM API, but is not implemented by all browsers. jquery makes the neces
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.