jQuery 验证忽略带有样式的元素

发布于 2024-08-28 05:05:28 字数 181 浏览 2 评论 0原文

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

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

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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不再见 2024-09-04 05:05:28

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


使用 :hidden

由于多种原因,元素可以被视为隐藏:

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

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

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

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


Use :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.
$("#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.

傾旎 2024-09-04 05:05:28

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

":隐藏”

就是您要寻找的内容。

由于多种原因,元素可以被视为隐藏:

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

我感觉这样可能会更好。

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

":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.

I feel this might be better.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文