Have you ever seen those two things (in the title) being used in JQuery? Here's a simple example:
Copy Code code as follows:
$ ("a"). Click (function () {
$ (' body '). Append ($ (this). attr ("href"));
return false;
}
That code would append the "href" attribute as text to the "Every time a link is clicked but not actually go" Nk. The return false; Part of this code prevents the browser from performing the "Default action for" link. That exact thing could is written like this:
Copy Code code as follows:
$ ("a"). Click (function (e) {
$ (' body '). Append ($ (this). attr ("href"));
E.preventdefault ();
}
So what ' s the difference?
The difference is this return false; Takes things a bit further in that it also prevents this event from propagating (or "bubbling up") the DOM. The you-may-not-know-this bit is whenever a event happens on a element, which is triggered on every single par ENT element as. So let's say you have a box inside a box. Both boxes have click events on them. Click on the Inner box, a click would trigger on the outer box too, unless for you prevent propagation. Like this:
Demo Address: http://css-tricks.com/examples/ReturnFalse/
So in the other words:
Copy Code code as follows:
function () {
return false;
}
is EQUAL to
Function (e) {
E.preventdefault ();
E.stoppropagation ();
}
It's all probably a lot the complicated than this and articles as this probably explain the it all a lot.
Reference:
1.The difference between ' return false; ' and ' e.preventdefault (); '
2.Event Order
Test Code package download