Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

jquery - jQuery获取所选单选按钮的值(jQuery get value of selected radio button)

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.

(组中的每个单选按钮共享相同的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) .

(除此之外,当选择单选按钮时,它不会向控件添加“ checked”属性,而只是对文本进行检查 (我猜只是对属性进行了检查,没有值) 。)

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 >

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

(有人可以帮助我使用可以帮助我获取选中的单选按钮值的jQuery代码吗?)

  ask by user1114212 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just use.

(随便使用。)

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

So easy it is.

(很容易。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...