2010-07-28 6 views
0

J'ai deux boutons radio à mon avis ..Comment vérifier que l'on est cochée ou non en utilisant jquery

quelque chose comme ça ..

<input type="radio" name="ObnCategory" id="Obncategory" checked="checked" />X</div><br /> 
    <div> 
    <input type="radio" name="ObnCategory" id="Obnsubcategory" />Y</div><br /> 

Je dois voir que l'on est vérifié ou non en utilisant jquery?

grâce

Répondre

2

Essayez ceci:

$("input:radio:checked").val(); 

i.e. .:

if ($("input:radio:checked").val() == "X") { 

} 
else if ($("input:radio:checked").val() == "Y") { 

} 

Dans votre exemple particulier mis à jour, essayez ceci:

$("input:radio:checked").next().text(); 
+0

basé sur je pense de l'OP qui ne peuvent pas être appliquées ... :) – Reigel

1

pourquoi ne pas ajouter un label ...

<div> 
    <input type="radio" name="ObnCategory" id="Obncategory" checked="checked" /> 
    <label for="Obncategory">X</label> 
</div> 
<div> 
    <input type="radio" name="ObnCategory" id="Obnsubcategory" /> 
    <label for="Obnsubcategory">Y</label> 
</div> 

puis

$(function(){ 
    $(':radio:checked').next('label').text() // would get the value 
}) 

play with the demo here

Questions connexes