what's the difference of return true or false here?
$('form').submit(f开发者_如何学Cunction() {
alert($(this).serialize());
return false; // return true;
});
what's the difference for this form submission function between return false
and true
?
If you return false
from the submit event, the normal page form POST will not occur.
return false
, don't do the form's default action. return true
, do the form's default action.
It's also better to do
$('form').submit(function(e) {
alert($(this).serialize());
e.preventDefault();
});
As already mentioned, returning false stops the event from "bubbling up". If you want the full details, take a look at the API documentation for bind()
: http://api.jquery.com/bind/.
"Returning false from a handler is equivalent to calling both .preventDefault() and .stopPropagation() on the event object."
return false; // cancel submit
return true; // continue submit
精彩评论