2012-10-29 3 views
1

j'ai quelques boutons radio:vérifier si un élément de bouton radio vérifié

<input type="radio" id="rdoLevel" name="rdoSelect" /> 
<input type="radio" id="rdoBase" name="rdoSelect" /> 
<input type="radio" id="rdoSchool" name="rdoSelect" /> 
<input type="radio" id="rdoTypeRegistre" name="rdoSelect" /> 

et je veux vérifier chaque élément par identifiant, par exemple, je veux vérifier si rdoLevel égal vérifié un code exécutée de par exemple comme ceci:

$("input:radio").click(function() { 
        var id = $(this).attr("id"); 
        if (id == "rdoLevel") { 
         //some code 
        } 
       }); 

comment puis-je faire cela?
merci à votre avis!

Répondre

2
$("input:radio").click(function() { 
       var id = $(this).attr("id"); 
       if (id == "rdoLevel" && $(this).is(':checked')) { 
        //some code 
       } 
      }); 
4
$("input[name='rdoSelect']").change(function() { 
    switch (this.id) { 
     case "rdoLevel": 
      // ... 
      break; 
     case "rdoBase": 
      // ... 
      break; 
     // etc 
    } 
});​ 

DEMO:http://jsfiddle.net/kQC9L/

1

Changer votre clic pour ce qui suit. (Le sélecteur de type était incorrect.)

$("input[type=radio]").click(function() { 
    var id = $(this).attr("id"); 
    alert(id); 

});​ 
Questions connexes