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 Event(allows bubbling). Event. Preventdefault () in the handling of the event, you can block the default event but allow the bubbling event to occur. C:Event. Stoppropagation ()---> InEventHandler, prevent bubbling (allowsdefaultbehavior). Event. Stoppropagation () in the handling of the event, you can prevent bubbling but allow the default event to occur. Code such as: $ ('. Menu Li'). Click (function () {$ ( This). Find ('ul'). Toggle (); return false;//Remove the trial effect}) --------------------------------------------------------------------------------------------------------------- -------------------JS code block event bubbling//Judging browser type, ie bubbles down, Firefox bubbles upfunction Stopevent (e) {e= e | | Window.Event; if(e.stoppropagation) e.stoppropagation (); ElseE.cancelbubble =true; if(E.preventdefault) E.preventdefault (); ElseE.returnvalue =false; }
JS Event bubbling