[英]what's the difference of return true or false here?
$('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
和true
之间这个表单提交函数的区别是什么?
如果从提交事件返回false
,则不会发生正常的页面表单POST。
return false
, don't do the form's default action. return false
,不要执行表单的默认操作。 return true
, do the form's default action. return true
,执行表单的默认操作。
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". 如前所述,返回false会阻止事件“冒泡”。 If you want the full details, take a look at the API documentation for
bind()
: http://api.jquery.com/bind/ . 如果您需要完整的详细信息,请查看
bind()
的API文档: http : //api.jquery.com/bind/ 。
"Returning false from a handler is equivalent to calling both .preventDefault() and .stopPropagation() on the event object."
“从处理程序返回false相当于在事件对象上调用.preventDefault()和.stopPropagation()。”
return false; // cancel submit
return true; // continue submit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.