$('form').submit(function() {
alert($(this).serialize());
return false; // return true;
});
what's the difference for this form submission function between return false
and true
?
如果从提交事件返回false
,则不会发生正常的页面表单POST。
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.