开发者

How to check which one is checked or not using jquery

开发者 https://www.devze.com 2023-01-09 08:25 出处:网络
I have two radio button in my view.. something like this.. <input type=\"radio\" name=\"ObnCatego开发者_高级运维ry\" id=\"Obncategory\" checked=\"checked\" />X</div><br />

I have two radio button in my view..

something like this..

 <input type="radio" name="ObnCatego开发者_高级运维ry" id="Obncategory" checked="checked" />X</div><br />
  <div>
  <input type="radio" name="ObnCategory" id="Obnsubcategory" />Y</div><br />

I need to see which one is checked or not using jquery?

thanks


Try this:

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

i.e.:

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

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

}

In your particular updated example try this:

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


why not add a 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>

then

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

play with the demo here

0

精彩评论

暂无评论...
验证码 换一张
取 消