2010-10-25 16 views
5

Me parece que no puede conseguir este trabajo parece que deberíajQuery función de cambio no funciona

$('.titleother').change(function() { 

if ($('.titleother').val() == 'Other') { 
    ​$('.hiddentext').css('display','block') 
}​​​ 

}) 

Para este HTML

<select class="titleother">​ 
<option value="1">1</option> 
<option value="2">2</option> 
<option value="Other">Other</option> 
</select> 

<p class="hiddentext" style="display:none">TEXT</p> 

¿Alguna idea?

+0

asegurarse de que no [trabajo] (http://jsfiddle.net/amuec/)? – jensgram

+1

Parece que no funciona para mí? –

+1

en lugar de if ($ ('. Titleother'). Val() == 'Otro') $ ('. Hiddentext'). Css ('display', 'block') la mejor manera es: $ ('.hiddentext'). alternar ($ (this) .val() == 'Otro'); – Floyd

Respuesta

13

Esto funciona para yo usando Chrome:

$(function(ready){ 
    $('.titleother').change(function() { 
     if ($(this).val() == 'Other') { 
      $('.hiddentext').show(); 
     } 
    }); 
}); 

http://jsfiddle.net/amuec/11/

(código de Darin no funcionó para mí tampoco)

+0

Gracias que funciona para mí –

5

Asegúrese de poner esto en un $(document).ready de manera que el DOM está listo cuando se conecta el .change() manejador:

$(function() { 
    $('.titleother').change(function() { 
     if ($(this).val() == 'Other') { 
      ​$('.hiddentext').show(); 
     }​​​ 
    }); 
}); 
+0

Parece que no funciona http://jsfiddle.net/ExtWV/1/ –

+0

¿Ese violín funciona para mí? ¿Seguro que tienes javascript habilitado? – Alex

+0

Definitivamente tengo habilitado javascript - Estoy usando Safari en Mac - pero también lo he probado en Chrome y no funciona –

4

Creo que se echa en falta ;
Check here

+0

¿Eso tampoco funciona? –

+0

¿Recibió algún error? Lo probé en firefox. Está funcionando bien para mí. – svk

+0

¿Está buscando cuando se selecciona 1 y 2, debe ocultarse? – svk