如何手动触发验证与jQuery验证? [英] How to manually trigger validation with jQuery validate?
问题描述
我想手动触发验证,包括使用 jQuery验证显示错误消息。
我试图完成的场景是这样一个表单:
<形式>
< input id = i1> < button id = b1>
< input id = i2> < button id = b2>
< / form>
点击 b1
时,只有<$ c应验证$ c> i1 。如果点击 b2
,则只应验证 i2
。但是所有的字段都必须发布。我怎样才能做到这一点?我想过如何处理 b1 / b2
的点击事件并手动验证表单的一部分。
该库似乎允许验证单个元素。只需将一个点击事件关联到您的按钮并尝试以下操作:
$(#myform)。validate()。element ( #I1);
这里的例子:
http://docs.jquery.com/Plugins/Validation/Validator/element#element
I want to manually trigger validation including showing error messages with jQuery Validate.
The scenario I am trying to accomplish is a form like this:
<form>
<input id=i1> <button id=b1>
<input id=i2> <button id=b2>
</form>
When clicking b1
, only i1
should be validated. hen clicking b2
, only i2
should be validated. However all fields must be posted. How can I do this? I thought about handling the click event for b1/b2
and manually validating a part of the form.
That library seems to allow validation for single elements. Just associate a click event to your button and try the following:
$("#myform").validate().element("#i1");
Examples here:
http://docs.jquery.com/Plugins/Validation/Validator/element#element
这篇关于如何手动触发验证与jQuery验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!