Javascript 获取特定类的选定单选按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13677337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get selected radio buttons of certain class
提问by praks5432
I'm trying to get the radio buttons that has a certain class that is selected.
我正在尝试获取具有选定类的单选按钮。
Getting the radio buttons of that class comes with
获取该类的单选按钮附带
$("input:radio.someClass");
I thought that this would work to get the selected radio button -
我认为这将有助于获得选定的单选按钮 -
$("input:radio.someClass:selected");
But that returns empty - what am I doing wrong?
但这会返回空 - 我做错了什么?
回答by Akhil Sekharan
According to JQuery documentation.
根据 JQuery 文档。
The :selectedselector works for option elements. It does not work for checkboxes or radio inputs;
在:selected选择适用于选项元素。它不适用于复选框或无线电输入;
Try:
尝试:
$("input:radio.someClass:checked");
回答by Murali Prasanth
instead of this
而不是这个
$("input:radio.someClass:selected");
$("input:radio.someClass:selected");
try this one
试试这个
$("input:radio.someClass:checked");
回答by Swarne27
try this,
尝试这个,
$('input[class=someClass]:checked', '#yourForm').val();
For best performance jquery documentation recommends Jquery Documentationusing type instead of :radio selector
为了获得最佳性能 jquery 文档建议使用类型而不是 :radio 选择器的Jquery 文档
$('input[name=radioName]:checked', '#yourForm').val();
回答by msangel
$("input:radio.someClass:checked");
??
??
回答by Ankush Jain
select all checked radio buttons having someclass and then loop through all and get their value
选择所有选中的具有某个类的单选按钮,然后遍历所有按钮并获取它们的值
var v= $('input[type=radio].someclass:checked');
$(v).each(function(i){
alert($(this).val())
});
回答by Ishan Jain
This may solve your problem.
这可能会解决您的问题。
$('input[name=radioName].someClass:checked').val();
OR
或者
$("input[type='radiobutton'].someClass:checked");
If not then comment.
如果没有,那么评论。

