我们可以获取jQuery Validate错误类型吗? [英] Can we get the jQuery Validate error type?

查看:73
本文介绍了我们可以获取jQuery Validate错误类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery验证插件.有什么办法可以从jQuery表单验证中获取错误类型?例如,

I am using the jQuery Validation Plugin. Is there any way to get the type of error from the jQuery form validation? For example,

$('registration-form').validate({
    rules: {
        email: {
            required: true,
            email: true
        }
    },
    messages: {
        email: {
            required: "This is a required field.",
            email: "This is not a valid email address"
        }
    },
    errorPlacement: function(error, element) {
        error.appendTo(element.parent());
    }
});

我只想将由必需"错误生成的错误消息放在html页面上的"div"内,而不是将其附加到"element.parent()".如果我可以得到错误类型,例如必填"或电子邮件"错误,我可以编写代码来做到这一点.

I would like to place only the error message generated from a "required" error inside a "div" somewhere on the html page rather than appending it to "element.parent()". If I can get the error type, e.g. "required" or "email" error, I can write the code to do this.

感谢您的帮助!谢谢!

aobs

推荐答案

您可以轻松编辑插件.您可以为每个验证再添加一个参数(请参阅正则表达式),以识别被捕获的参数.

You may edit plugin easily. You can add one more parameter for each validation(see the regexes) to identify which one is caught.

这篇关于我们可以获取jQuery Validate错误类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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