jQuery获取选定单选按钮的值单选、按钮、jQuery

2023-09-07 09:18:03 作者:贱人自有定义

问题陈述很简单.我需要查看用户是否从单选组中选择了单选按钮.组中的每个单选按钮共享相同的 id.

The problem statement is simple. I need to see if user has selected a radio button from a radio group. Every radio button in the group share same id.

问题是我无法控制表单的生成方式.以下是单选按钮控件代码的示例代码:

The problem is that I don't have control on how the form is generated. Here is the sample code of how a radio button control code looks like:

<input type="radio" name='s_2_1_6_0' value='Mail copy to my bill to address' id = "InvCopyRadio" onchange = 'SWESubmitForm(document.SWEForm2_0,s_4,"","1-DPWJJF")' style="height:20;width:25" tabindex=1997 >

除了选择单选按钮时,它不会将选中"属性添加到控件只是文本检查 (我猜只是在没有值的情况下检查的属性).以下是所选无线电控件的外观

In addition to this when a radio button is selected it doesn't add a "checked" attribute to the control just text checked (I guess just the property checked without a value). Below is how a selected radio control looks like

<input type="radio" checked name='s_2_1_6_0' value='Mail copy to my bill to address' id = "InvCopyRadio" onchange = 'SWESubmitForm(document.SWEForm2_0,s_4,"","1-DPWJJF")' style="height:20;width:25" tabindex=1997 >

任何人都可以帮助我使用 jQuery 代码来帮助我获取选中的单选按钮的值吗?

Can anybody help me with jQuery code that can help me to get the value of checked radio button?

推荐答案

随便用吧.

$('input[name="name_of_your_radiobutton"]:checked').val();

就这么简单.