jQuery:循环 HTML 表中的所有单选按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2852052/
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
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 14:24:29 来源:igfitidea点击:
jQuery:Looping all radio buttons inside an HTML table
提问by Shyju
I have an HTML table having n rows and each rows contain one radiobutton in the Row.Using jQuery , How can i look thru these radio buttons to check which one is checked ?
我有一个包含 n 行的 HTML 表,每一行在 Row.Using jQuery 中包含一个单选按钮,我如何查看这些单选按钮以检查哪个单选按钮被选中?
回答by Sunny
$('#table tbody tr input[type=radio]').each(function(){
alert($(this).attr('checked'));
});
HTH.
哈。
回答by karim79
回答by SaiyanGirl
To loop through all the radio checked radio buttons, you can also do this:
要遍历所有选中的单选按钮,您还可以执行以下操作:
$('input:radio:checked').each(function() {
//this loops through all checked radio buttons
//you can use the radio button using $(this)
});
回答by Jarrett Meyer
$('.my-radio-class:checked')
回答by Felix Kling
回答by PetersenDidIt
var checked = $('#table :radio:checked');
回答by Scott Christopherson
//get the checked radio input, put more specificity in the selector if needed
var $checkedRadio = $("input[type=radio]:checked");
//if you want the value of the checked radio...
var checkedRadioVal = $checkedRadio.val();
回答by Jon
$("table tr input[type=radio]:checked");