jQuery .is(":visible")适用于Firefox但不适用于Chrome

Jes*_*son 6 javascript jquery

可能重复:
jquery .is(":visible")无法在Chrome中运行

我试图获取数组中的所有可见项.它在Firefox中运行良好,但不适用于Chrome.

这是我的代码:

$.each (t.config.promoInput, function (i, v) {
    var size = 0;

    $.each ($(v).find('option'), function (i, v) {
        $(v).show() // Show all options in <tt>$(v)</tt>.
            .not(':first-child') // Don't hide <tt>(All)</tt>.
            .not(':Contains("' + t.config.searchSpanInput.val() + '")') // Don't hide options that match the searchCriteria.
            .hide(); // Hide everthing that doesn't match or isn't (All).

        if ($(v).is(":visible")) {
            size++;
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

在Firefox大小增量中,而Chrome大小保持等于0.

编辑::包含是我自己添加到jQuery库.它是一个不区分大小写的版本:contains.

Mar*_*iss 0

隐藏和显示(启用/禁用)选项不能很好地支持跨浏览器(禁用/启用)。请参阅此问题,了解问题的一种可能解决方案:jQuery disable SELECT options based on Radio selected (Need support for all browsers)

一旦你削减了选项,你就可以使用长度来获得尺寸。