javascript jQuery 验证和忽略字段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10557059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 10:15:04  来源:igfitidea点击:

jQuery validation & ignore field

javascriptjqueryjquery-uidatetimepicker

提问by ethd

I have a form with id myformand two fields (dates) with dateclass. I would like to avoid jquery.validation (unobstrusive jquery validation on ASP .NET MVC3) for these two fields. I tried :

我有一个带有 id 的表单myform和两个带有date类的字段(日期)。我想避免这两个字段的 jquery.validation(ASP .NET MVC3 上的不显眼的 jquery 验证)。我试过 :

    $('#myform').validate({
        ignore: ".date"
    });

However it doesn't work, I always have an error (Please enter a valid date.).

但是它不起作用,我总是有一个错误(Please enter a valid date.)。

I need help please !

我需要帮助请!

Thanks,

谢谢,

Ed

埃德

采纳答案by Elliot Bonneville

You need ignoreTitle, according to This Doc.

ignoreTitle根据本文档,您需要。

回答by Wellington Lorindo

It works fine to me as described at the documentation http://jqueryvalidation.org/validate

如文档http://jqueryvalidation.org/validate 中所述,它对我来说很好用

$("#myform").validate({
   ignore: ".ignore"
});

And, for multiple field use:

并且,对于多领域使用:

$("#myform").validate({
   ignore: ".ignore, .another_class"
});

回答by Scutterman

For anyone who is trying this alongside jquery.validate.unobtrusive, you may find it's ignoring all options passed into $("#myform").validate()and you'll have to set them on the object instead:

对于与 一起尝试此操作的任何人jquery.validate.unobtrusive,您可能会发现它忽略了传入的所有选项,$("#myform").validate()而您必须将它们设置在对象上:

$('#myform').validate().settings.ignore = ".date";
$('#myform').valid();

The Unobtrusive plugin calls validate()when the document loads, which sets the options to defaults. A validator will then be created and cached, and any further calls to validate()will ignore new options and return the cached validator.

Unobtrusive 插件validate()在文档加载时调用,将选项设置为默认值。然后将创建并缓存一个验证器,任何进一步的调用都validate()将忽略新选项并返回缓存的验证器。