使用原始JavaScript提交函数时,jQuery验证不会触发 [英] jQuery validation not firing when using raw JavaScript submit function

查看:86
本文介绍了使用原始JavaScript提交函数时,jQuery验证不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单上有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?

推荐答案

原生提交方法 W3规范)将提交表格,而不是其他任何内容。它不会触发可取消的提交事件(请参阅表单提交的概念)。

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验证不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆