2012-02-02 54 views
6

可能重复:
jquery .is(“:visible”) not working in ChromejQuery的。是( “:可见”)在Firefox而不是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++; 
     } 
    }); 
}); 

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

编辑::包含是我自己除了jQuery库。它是一个不区分大小写的:contains的版本。

+2

HTML的外观如何? – Pointy 2012-02-02 15:44:23

+0

请注意,你必须关闭'每个'代码块 – 2012-02-02 15:46:18

+0

另外,我不确定,但我认为引用嵌套函数中的i和v将访问父范围中的那些,所以不需要传递它们? – 2012-02-02 15:47:24

回答

0

你为什么不只需检查为"display"财产,如果是"none"比它是隐藏的,如果它的"inline"比它是可见的:

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

    $.each ($(v).find('option'), function (i, va) { 
     $(va).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). 

    }); 
    //add only visible options 
    if ($(va).css("display") === "inline") { 
     size++; 
    } 
}); 

看吧http://jsfiddle.net/gwbTm/2/(我使用Chrome测试过)。
我认为设定的<option>知名度是建立问题,浏览器(expecially机智IE)

+0

这会在Chrome和Firefox中产生不同的结果 – Kloar 2013-04-26 15:17:47

相关问题