jQuery Validate Ignore 带有样式的元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2623514/
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-08-26 13:53:52  来源:igfitidea点击:

jQuery Validate Ignore elements with style

jqueryjquery-validate

提问by Gabe

I am using jQuery validate for client side validation and I want to ignore any element that has the style="display: none"

我正在使用 jQuery validate 进行客户端验证,我想忽略任何具有 style="display: none"

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

What would my selector be for that in the above case?

在上述情况下,我的选择器是什么?

回答by Felix Kling

Note:As of version 1.9.0, ignore: ":hidden"is the default option, so it does not have to be set explicitly anymore.

注意:从 1.9.0 版本开始,ignore: ":hidden"它是默认选项,因此不必再明确设置。



Use :hidden:

使用:hidden

Elements can be considered hidden for several reasons:

  • They have a display value of none.
  • They are form elements with type="hidden".
  • Their width and height are explicitly set to 0.
  • An ancestor element is hidden, so the element is not shown on the page.

元素可以被认为是隐藏的,原因有几个:

  • 它们的显示值为 none。
  • 它们是 type="hidden" 的表单元素。
  • 它们的宽度和高度明确设置为 0。
  • 祖先元素被隐藏,因此该元素不会显示在页面上。
$("#myform").validate({
   ignore: ":hidden"
});


Update:for completeness, from the plugin's documentation:

更新:为了完整性,来自插件的文档

ignore
Elements to ignore when validating, simply filtering them out. jQuery's not-method is used, therefore everything that is accepted by not()can be passed as this option. Inputs of type submit and reset are always ignored, so are disabled elements.

忽略
验证时要忽略的元素,只需将它们过滤掉即可。使用 jQuery 的not-method,因此接受的所有内容都not()可以作为此选项传递。提交和重置类型的输入总是被忽略,禁用元素也是如此。

回答by AjayP

http://api.jquery.com/hidden-selector/

http://api.jquery.com/hidden-selector/

":hidden"

":hidden"

is what your looking for.

是您要找的。

Elements can be considered hidden for several reasons:

  • They have a display value of none.
  • They are form elements with type="hidden".
  • Their width and height are explicitly set to 0.
  • An ancestor element is hidden, so the element is not shown on the page.

元素可以被认为是隐藏的,原因有几个:

  • 它们的显示值为 none。
  • 它们是 type="hidden" 的表单元素。
  • 它们的宽度和高度明确设置为 0。
  • 祖先元素被隐藏,因此该元素不会显示在页面上。

I feel this might be better.

我觉得这可能会更好。