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

标签 jquery jquery-validate

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

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

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

最佳答案

注意:从版本 1.9.0 开始,ignore: ":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.
$("#myform").validate({
   ignore: ":hidden"
});
<小时/>

更新:为了完整性,来自 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 验证忽略带有样式的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2623514/

相关文章:

javascript - 从外部输入动态更改脚本

javascript - 在 Javascript 中打印 actionMessages

输入附加上的 jQuery 验证(Twitter Bootstrap)

jquery - 如何在 jQuery 的验证插件中延迟 onkeyup 事件

javascript - 使用 jQuery 在选择列表上进行验证

asp.net-mvc - knockout + mvc 3 + 验证

javascript - 淡出当前元素 淡入下一个元素并反向

jquery - Bootstrap 3 列移动问题

jQuery 将类设置为变量

javascript - 如何使用 showErrors 函数显示集中错误消息并更改输入边框颜色