使JQuery Validation插件评估不延迟 [英] Making the JQuery Validation plugin evaluation non-lazy
本文介绍了使JQuery Validation插件评估不延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据JQuery验证插件的文档:
According to the documentation for the JQuery validation plugin:
验证是懒惰的:在首次提交表单之前,用户可以在各个字段之间切换,而不会收到烦人的消息
the validation is lazy: Before submitting the form for the first time, the user can tab through fields without getting annoying messages
有什么方法可以通过表单在用户选项卡上显示消息?
Is there any way to display the messages as the user tabs through the form?
欢呼
推荐答案
You can override the default onfocusout
to do more eager/pre-submit validation you want, like this:
$(function() {
$("form").validate({
rules: { ...rules... },
messages: { ...messages... },
onfocusout: function(element) { $(element).valid(); }
});
});
默认onfocusout
看起来像这样,禁用blur
验证,直到提交一次:
The default onfocusout
looks like this, disabling the blur
validation until after it's been submitted once:
onfocusout: function(element) {
if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) {
this.element(element);
}
}
这篇关于使JQuery Validation插件评估不延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文