OnSubmit 是在每次提交表单时运行还是仅在单击提交按钮时运行?
我有一个表单,它有一个普通的提交按钮,还有几个提交表单的 ajax 方法。我需要做一些预保存验证工作。每次提交表单时都会调用 onSubmit 函数还是需要在 ajax 表单提交之前手动调用该方法?
I have a form that has a normal submit button, but also several ajax methods that submit the form as well. I need to do some pre-save validation stuff. Will the onSubmit function be called every time the form is submitted or do I need to manually call the method before my ajax form submissions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
onsubmit
事件仅在您手动提交表单时发生。如果调用
submit
方法提交表单,则不会触发onsubmit
事件。如果您使用表单中的数据进行 AJAX 调用,则根本不会提交表单。
The
onsubmit
event only happens when you submit the form manually.If you call the
submit
method to submit the form, theonsubmit
event is not triggered.If you are making an AJAX call using the data from the form, the form isn't even submitted at all.
onSubmit
就是你想要的。如果您使用 AJAX,则应在此方法中发送请求并返回 false
或以其他方式停止默认行为。onSubmit
is what you want. If you're using AJAX, you should send the request within this method andreturn false
or otherwise stop the default behavior.