简体   繁体   English

jQuery选择器,隐藏元素除外

[英]jQuery selector for hidden elements except

By default, jQuery Validation ignores hidden elements : 默认情况下, jQuery Validation 忽略隐藏的元素

ignore (default: ":hidden") 忽略(默认:“:hidden”)

Type: Selector 类型:选择器

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. 使用jQuery的not-method,因此not()接受的所有内容都可以作为此选项传递。 Inputs of type submit and reset are always ignored, so are disabled elements. 始终忽略类型为commit和reset的输入,因此禁用的元素也是如此。

Here's the relevant code from jquery.validate.js: 这是jquery.validate.js的相关代码:

elements: function() {
    var validator = this,
        rulesCache = {};

    // select all valid inputs inside the form (no submit or reset buttons)
    return $( this.currentForm )
    .find( "input, select, textarea" )
    .not( ":submit, :reset, :image, [disabled]" )
    .not( this.settings.ignore )
    .filter( function() {
        // snip
    });
}

The problem I'm having is due to the fact that I'm also using TinyMCE. 我遇到的问题是由于我也在使用TinyMCE。 When TinyMCE is applied to a textarea, it hides the textarea and creates an iframe in its place. 将TinyMCE应用于文本区域时,它将隐藏该文本区域并在其位置创建一个iframe。 This means jQuery Validation ignores it by default. 这意味着jQuery Validation默认会忽略它。

I can force the validation to pickup the hidden textareas by changing the value of the ignore option to null : 我可以通过将ignore选项的值更改为null来强制验证以拾取隐藏的文本区域:

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

Unfortunately this creates a huge performance issue on my page which has hundreds of hidden input fields. 不幸的是,这在我的页面上造成了巨大的性能问题,该页面上有数百个隐藏的输入字段。 It's so bad it actually crashes Chrome and IE (Firefox is a champ, but still slow). 太糟糕了,实际上导致Chrome和IE崩溃(Firefox是冠军,但仍然很慢)。

I think what I need to solve this problem is a jQuery selector for hidden elements except those with a certain class name , or something like this: 我认为我需要解决的问题是隐藏元素的jQuery选择器, 除了那些具有特定类名的元素之外 ,或者类似这样的东西:

$("#myform").validate({
    ignore: ':hidden(:not(textarea.tinymce))'
});

I realize this is an invalid selector. 我意识到这是一个无效的选择器。 Is there a selector like this? 有这样的选择器吗? If not, is there a better way that I'm not seeing to tell jQuery Validation to ignore all the hidden elements except those hidden by TinyMCE? 如果不是,是否有更好的方法让我看不到jQuery Validation忽略除TinyMCE所隐藏的元素以外的所有隐藏元素?

特殊选择器通常排在其他选择器之后(除了notis以及另外两个选择器:

":hidden:not(textarea.tinymce)"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM