简体   繁体   English

如何使用jquery验证插件显示不同的错误消息

[英]How do I display different error messages using jquery validation plugin

I am trying to add validation to my form with jQuery Validation Plugin, but I'm having a problem where the plugin puts the same error messages Please enter a valid URL. 我正在尝试使用jQuery验证插件将验证添加到我的表单中,但是我遇到了问题,即该插件放置了相同的错误消息, Please enter a valid URL.
My code: http://jsfiddle.net/52VtD/3124/ 我的代码: http //jsfiddle.net/52VtD/3124/
Any solution for that? 有什么解决办法吗?

Thanks 谢谢

'install' is not a valid jQuery selector: 'install'不是有效的jQuery选择器:

$('install').validate({...

You are targeting id="install" so you need a hash: 您的目标是id="install"因此需要一个哈希:

$('#install').validate({...

Your jsFiddle demo is working now: 您的jsFiddle演示现在正在工作:

http://jsfiddle.net/52VtD/3129/ http://jsfiddle.net/52VtD/3129/


Quote OP: 报价OP:

"I'm having a problem where the plugin puts the same error messages 'Please enter a valid URL'." “我在插件上输入相同的错误消息'请输入有效的URL'时遇到问题。”

No idea what you're talking about since there is nothing in your code that has anything to do with validating a URL. 不知道您在说什么,因为您的代码中没有与验证URL有关的任何内容。 You need to fix your question by posting the relevant code and clearly explaining what you expect this code to do. 您需要通过发布相关代码并明确说明您希望此代码执行的操作来解决问题。

As @Sparky already pointed out you used the wrong selector. 正如@Sparky已经指出的那样,您使用了错误的选择器。

If your problem is that the same error message is displayed in every field, you can specify what error message is displayed specifically for each field, for example: 如果您的问题是在每个字段中都显示相同的错误消息,则可以指定专门为每个字段显示的错误消息,例如:

$('#install').validate({
        rules: {
            title: {
                minlength: 3,
                maxlength: 15,
                required: true
            }
    },
    messages:{ title: {
        required: "Custom message for required rule",
        maxlength: "Another custom message"
    }}
...    

You can also control where the error messages are displayed, for example by using the errorLabelContainer and errorElement options in validate. 您还可以控制显示错误消息的位置,例如,通过在validate中使用errorLabelContainer和errorElement选项。 See doc here : 在这里查看文档:

Use errorClass, errorElement, wrapper, errorLabelContainer, errorContainer, showErrors, success, errorPlacement, highlight, unhighlight, and ignoreTitle to control how invalid elements and error messages are displayed. 使用errorClass,errorElement,wrapper,errorLabelContainer,errorContainer,showErrors,success,errorPlacement,highlight,unhighlight和ignoreTitle来控制无效元素和错误消息的显示方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery验证插件,如何将错误消息转换为不同的语言 - jquery validation plugin , how to convert error messages to different lanuages 如何使用jQuery Validation插件在元素下方显示错误消息 - How to display error message below the element using jQuery Validation plugin 表单验证消息(使用jQuery验证插件) - Form Validation Messages (using jQuery Validation Plugin) 如何使用Unslide JQuery插件显示上一个和下一个? - How do i display previous and next using Unslide JQuery plugin? 我们如何使用jquery / javascript插件在文本框下方显示错误消息? - How can we display error messages below textbox using jquery/javascript plugin? 如何使用jQuery以HTML5样式显示自定义验证消息? - How to display custom validation messages in HTML5 style using jQuery? 如何使用 addClassRules 显示带有 jQ​​uery 规则验证的自定义消息 - How to display custom messages with jQuery rules validation using addClassRules jQuery验证已加载,但不显示错误消息 - jQuery validation is loaded but doesnt display error messages 如何使用jQuery验证插件来验证字符串集合? - How do I use jQuery validation plugin to validation a collection of strings? jQuery:插件验证,如何验证十几个不同的字段? - jQuery: Plugin Validation, how do I validate a dozen or so different fields?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM