问题描述
我的表单上有jQuery验证。当我点击提交按钮时,会调用保存功能:
I have jQuery validation on my form. When I click submit button, 'save' function is called:
function save(){
var form = document.getElementById('myForm');
form.submit(); // <- jquery validation is not called
$(form).submit() // <- jquery validation works
}
为什么form.submit()没有验证我的表格?
Why form.submit() is not validating my form?
推荐答案
()。
The native submit
method (W3 spec) will submit the form, and nothing else. It does not fire a cancelable submit
event (see concept of form submit).
jQuery的是 .trigger(submit)的别名
,但此外,表单上的默认提交操作将被解除 [已调用] ,因此表单将被提交。
jQuery's submit
method is an alias for .trigger("submit")
, but "in addition, the default submit action on the form will be fired [invoked], so the form will be submitted."
您的验证将侦听那些使用本机提交方法时不会发生的提交事件。
Your validation will listen for those submit events, which don't happen when using the native submit method.
这篇关于使用原始JavaScript提交函数时,jQuery验证不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!