开发者

Get ID value from set of radio buttons

I'm trying to get the id of the set of radio buttons. Here is the HTML for it.

<input id="1" type="radio" title="2" value="6/1/2010" name="vacationDay">
<input id="2" type="radio" title="2" value="6/2/2010" name="vacationDay">
<input id="3" type="radio" title="2" value="6/3/2010" name="vacationDay" checked='checked'>

Here is my Javascript.

var updateDay = $('input[name=vacationDay]:checked').val();

It returns the value (6/3/2010) of the selected radio button . I would like to get 开发者_JAVA技巧the id of the checked button (3) as well. Ideas?


var $radio = $('input[name=vacationDay]:checked');
var updateDay = $radio.val();
var id = $radio.attr('id');

.attr()


   var btnId = $('input[name=vacationDay]:checked').attr('id');


not sure if this is what you wish for :

var id = $('input[name=vacationDay]:checked').attr('id');


You can change your .val() to .attr('id')!

var updateDay = $('input[name=vacationDay]:checked').attr('id');​


try

var updateDay = $('input[name=vacationDay]:checked').attr('id')

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜