2012-02-02 22 views
6

Duplicar posibles:
jquery .is(“:visible”) not working in Chrome.is jQuery ("Visible") funciona en Firefox, pero no Chrome

estoy tratando de obtener todos los elementos visibles en una matriz. Funciona bien en Firefox pero no en Chrome.

Aquí está mi código:

$.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++; 
     } 
    }); 
}); 

En incrementos de tamaño de Firefox, mientras que el tamaño Chrome se mantiene igual a 0.

EDIT:: Contiene es mi propio Además de la biblioteca jQuery. Es una versión insensible a mayúsculas/minúsculas de: contiene.

+2

¿Cómo se ve el HTML? – Pointy

+0

Tenga en cuenta que debe cerrar ambos bloques de código 'each' –

+0

Además, no estoy seguro, pero creo que al hacer referencia a i y v en las funciones anidadas, se accederá a los que están en el ámbito primario, ¿por lo que no es necesario pasarlos? –

Respuesta

0

¿Por qué no simplemente marque para la propiedad "display", si es "none" de lo que está oculto, si es "inline" de lo que es visible:

$.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++; 
    } 
}); 

mira aquí http://jsfiddle.net/gwbTm/2/ (i probado con Chrome).
creo que al establecer la visibilidad de <option> es algo que crea un problema con los navegadores (IE EXPECIALLY ingenio)

+0

Esto crea diferentes resultados en Chrome y Firefox – Kloar

Cuestiones relacionadas