jQuery验证样式忽略元素 [英] jQuery Validate Ignore elements with style
问题描述
我正在使用jQuery validate进行客户端验证,并且我想忽略任何具有style="display: none"
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?
推荐答案
注意:从1.9.0版开始,ignore: ":hidden"
是默认选项,因此不必明确设置.不再.
Note: As of version 1.9.0, ignore: ":hidden"
is the default option, so it does not have to be set explicitly anymore.
使用 :hidden
:
可以将元素视为隐藏的原因有几个:
Elements can be considered hidden for several reasons:
- 它们的显示值为无.
- 它们是具有type ="hidden"的表单元素.
- 其宽度和高度明确设置为0.
- 祖先元素被隐藏,因此该元素未显示在页面上.
- 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:
忽略
验证时要忽略的元素,只需将其过滤掉即可.使用jQuery的 not 方法,因此not()
接受的所有内容都可以作为此选项传递.始终会忽略类型为Submit和reset的输入,因此也会禁用禁用的元素.
ignore
Elements to ignore when validating, simply filtering them out. jQuery's not-method is used, therefore everything that is accepted bynot()
can be passed as this option. Inputs of type submit and reset are always ignored, so are disabled elements.
这篇关于jQuery验证样式忽略元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!