Sometimes it's annoying to encounter bubbling events, really ...
1.e.stoppropagation () block event bubbling
<Head> <title></title> <Scriptsrc= "Scripts/jquery-1.4.1.js"type= "Text/javascript"></Script></Head><Body> <Table> <TR> <TD><span>Bubbling event Test</span></TD> </TR> </Table></Body>
Let's look at this code first:
<script type= "Text/javascript" > $ (function () { $ ("table"). Click ( function () {Alert ("table alert");}); $ ("TD"). Click (function () {alert ("TD alert");}); $ ("span"). Click (function () { alert ("span alert"); } ); </script>
We will see a situation like this: Span alert, TD Alert, table alert. This is called event bubbling. is from bottom to top, from inside to outside, the events are triggered sequentially.
Sometimes we don't want events to bubble up.
<script type= "Text/javascript" > $ (function () { $ ("table"). Click ( function () {Alert ("table alert");}); $ ("TD"). Click (function () {alert ("TD alert");}); $ ("span"). Click (function (e) { alert ("span alert"); E.stoppropagation (); } ); </script>
If you want to get event-related information, you should add an E object to the anonymous method, and E is the event object.
2.e.preventdefault () blocks event default behavior.
$ ("a"). Click (function (e) { alert ("default behavior is forbidden"); E.preventdefault ();}); <a href= "http://www.baidu.com" > Testing </a>
3.return false
Return false is equivalent to calling both E.preventdefault () and E.stoppropagation ().
Return false prevents event bubbling in addition to blocking the default behavior. If you have a jquery source code on hand, you can see the following code:
if (ret===false) {event.preventdefault (); Event.stoppropagation ();}
JQuery JS in return False,e.preventdefault (), e.stoppropagation () difference (event bubbling)