使用jquery的.validate函数提交表单 [英] submitting a form using jquery's .validate function
问题描述
这是一个简单的问题。我有一个使用jquery的.validate函数验证的表单。
this is a simple question. I have a form that is being validated using jquery's .validate function.
问题是,当我使用以下方式提交表单时,验证似乎无效:< input type ='submit'/>
The problem is that validating only seems to work when I submit the form using: <input type='submit' />
但是,我想使用我自己的自定义按钮代替:< button type =submit>点击提交< / button>
....或使用类似... < a onclick =submitFunction()>点击提交< / a>
However, I would like to use my own custom button using instead: <button type="submit">click to submit</button>
.... or use something like... <a onclick="submitFunction ()">click to submit</a>
然而,最后两个选项不会触发jquery的验证功能。有没有解决的办法?感谢您的帮助!
These last two options however, do not trigger jquery's validate function. Is there a way around this? Thanks for the help in advance!
推荐答案
jQuery Validation插件与 在jQuery中提交
事件。如果你想从其他地方(即任何其他事件处理程序)触发它,你必须手动调用 .submit()
,这将触发验证。
The jQuery Validation plugin is tied to the submit
event in jQuery. If you want to trigger this from anywhere else (i.e. any other event handler), you will have to call .submit()
manually, which will trigger the validation to occur.
请注意,在致电 .validate()
在您的表单上设置验证,您可以存储 Validator
它返回的实例并调用 表单
方法如果您想要与提交表单分开执行验证。
Note that after calling .validate()
to set up validation on your form you can store the Validator
instance it returns and call the form
method on it if you want to perform the validation separately from the submission of the form.
这篇关于使用jquery的.validate函数提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!