开发者

How to get selected input:radio

How come this works.

$('input:checked')

and this won't?

$('inp开发者_Python百科ut').is(':checked')

Thanks.


The second version should use .filter() instead of .is().

$('input').filter(':checked')

It seems like .is() should work since there's a .not() method. But .not() is actually the opposite of .filter().


You want to check if any radio button on the page is selected? No need to do that, there's always one that's selected (radio button = exactly one option selected).

Want to test if a radio button with a certain ID is selected?

$('#your-radio-button').is(':checked')

Want a list of all checked radio buttons? This returns a jQuery object containing the radio inputs.

$('input:radio:checked')

If you want to restrict it to inputs with a certain name:

$('input[name=something]:radio:checked')


Define works. One returns a list and the other returns a boolean.


You can try this one.Its worked & tested also.

$("input[type=radio]:checked").val()

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

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

Or You can get help from this sample http://daxpanganiban.com/javascript/get-value-of-radio-button-using-jquery

Cheers!


Try this:

$('input[name='radioName']:checked')
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜