2012-02-02 56 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

相關問題