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 ();
}
);
3. By using the Stoppropagation () method, only one event is prevented from bubbling.
JQuery Code:
$ ("form"). Bind (
"submit",
function (event) {
event.stoppropagation ();
}
);
(4) Summary
1. an event bubbling corresponds to triggering the same event at the top
Special: If two is set to double-click an event, the event that triggers one click is bubbling when you click Two
(Double-click the Include).
2. If in the Click event, add E.preventdefault () before the event you want to handle;
Then cancel the behavior (Popular understanding: equivalent to doing a return operation), do not execute the following statement.
3. e.stoppropagation () the upper Click event is not triggered as long as in the Click event.
If an event object is provided, this is a non-ie browser if
(e && e.stoppropagation)
//So it supports the Stoppropagation () method
of the Web E.stoppropagation ();
else
//Otherwise, we need to use IE to cancel event bubbling
window.event.cancelBubble = true;
return false;
The above jquery cancellation event bubbling three methods (recommended) is a small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.