2013-03-15 4 views
1

J'ai un morceau de code qui fonctionne dans Jquery 1.7.2, mais il ne semble pas fonctionner dans 1.9.1.Case à cocher lorsque le bouton radio est coché

Maintenant, je suis curieux de savoir ce qui a changé.

Quelqu'un peut-il m'aider?

http://jsfiddle.net/an9dV/

$(document).ready(function() { 
$("#ikga-akkoord").hide(); 
$("#verzekeringen").click(function() { 
    if ($("#verzekeringen").attr('checked')) { 
     $("#ikga-akkoord").fadeIn(); 
    } 


}); 

});

Répondre

2

Voir ceci:

http://jsfiddle.net/an9dV/6/

$(document).ready(function() { 
$("#ikga-akkoord").hide(); 
    $(".verzekeringen").on('click', function() { 

     if ($(this).is(':checked')) { 
      $("#ikga-akkoord").fadeIn(); 
     } 
    }); 
}); 

Vous ne pouvez pas avoir plusieurs id sur la même page, c'est la raison pour laquelle je change les id à une classe.

<div class="kiesbundelblokken"> 
<div id="belsms"> 
    <p>Verzekeringen</p> 
    <div class="radiobuttonsverzekeringen"> 
     <label> 
      <input class="verzekeringen" type="radio" name="verzekeringen" value="normaal" 
      />ACE Toestelverzekering</label> 
     <label> 
      <input class="verzekeringen" type="radio" name="verzekeringen" value="plus" 
      />ACE Toestelverzekering Plus</label> 
     <label id="ikga-akkoord"> 
      <input id="akkoordvoorwaarden" type="checkbox" name="akkoordvoorwaarden" 
      value="akkoordvoorwaarden" />Ik ga akkoord met deze voorwaarden</label> 
    </div> 
</div> 

modifier

Basé sur @soyuka obtenir des commentaires, j'ai changé attr ('checked') à .est (': checked'). Une méthode plus agréable et plus propre. .attr ('checked') retournera undefined si quelque chose n'est pas coché, donc invalide.

+0

+1 pour les ID multiples, mais son code ne fonctionne pas en raison de 'attr ('checked')'. – soyuka

+0

@soyuka il n'y a pas d'attr ('checked') dans mon code? – Tim

+0

Je sais, vous devriez juste mentionner que vous l'avez changé :). – soyuka

1

Vous devez utiliser is au lieu de votre attr:

$("#verzekeringen").click(function() { 
    if ($("#verzekeringen").is(':checked')) { 
     $("#ikga-akkoord").fadeIn(); 
    } 


}); 

Consultez votre mise à jour fiddle.

Questions connexes