1. Cancel the default behavior by returning false and prevent the event from bubbling.
JQuery Code:
?
| 1234567891011 |
$("form").bind( "submit", function() { return false; }); |
2. Only the default behavior is canceled by using the Preventdefault () method.
JQuery Code:
?
| 123456789 |
$("form").bind( "submit", function(event){ event.preventDefault(); }); |
3. Only one event bubble is blocked by using the Stoppropagation () method.
JQuery Code:
?
| 123456789 |
$("form").bind( "submit", function(event){ event.stopPropagation(); }); |
(4) Summary
1. One event blistering corresponds to the same event that triggered the upper layer
Special: If both are set to double-click events, the event that triggers one click is bubbled when you click
(Double-click to include the clicked).
2. If in the Click event, precede the event you want to process with e.preventdefault ();
Then cancel the behavior (Popular understanding: equivalent to do a return operation), do not execute after the statement.
3. e.stoppropagation () the upper-level click event is not triggered as long as in the Click event.
?
| 1234567891011 |
//如果提供了事件对象,则这是一个非IE浏览器if ( e && e.stopPropagation ) // 因此它支持W3C的stopPropagation()方法 e.stopPropagation();else //否则,我们需要使用IE的方式来取消事件冒泡 window.event.cancelBubble = true;returnfalse; |
jquery three ways to cancel event bubbling (recommended)