jQuery:循环 HTML 表格内的所有单选按钮

发布于 2024-09-02 01:54:19 字数 74 浏览 5 评论 0原文

我有一个 HTML 表,有 n 行,每行在 Row 中包含一个单选按钮。使用 jQuery,我如何查看这些单选按钮来检查哪一个被选中?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

风柔一江水 2024-09-09 01:54:19
$('#table tbody tr input[type=radio]').each(function(){
 alert($(this).attr('checked'));
});

HTH。

$('#table tbody tr input[type=radio]').each(function(){
 alert($(this).attr('checked'));
});

HTH.

从来不烧饼 2024-09-09 01:54:19

要循环遍历所有已选中的单选按钮,您还可以执行以下操作:

$('input:radio:checked').each(function() {
    //this loops through all checked radio buttons
    //you can use the radio button using $(this)
});

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)
});
拥抱没勇气 2024-09-09 01:54:19

有很多方法可以做到这一点,例如,使用 .each.is 遍历方法:

$("table tbody tr td input[name=something]:radio").each(function() {
    if($(this).is(":checked")) {
        $(this).closest("tr").css("border", "1px solid red");
    } else {
        // do something else
    }
});

There are many ways to do that, e.g., using .each and the .is traversal method:

$("table tbody tr td input[name=something]:radio").each(function() {
    if($(this).is(":checked")) {
        $(this).closest("tr").css("border", "1px solid red");
    } else {
        // do something else
    }
});
喵星人汪星人 2024-09-09 01:54:19

您想要处理每个单选按钮还是只需要选中的单选按钮?如果是后者,则非常简单:

$('table input:radio:checked')

参考::radio, :checked

Do you want to process every radio button or do you only need the checked ones? If the latter, it is quite easy:

$('table input:radio:checked')

Reference: :radio, :checked

沉默的熊 2024-09-09 01:54:19
var checked = $('#table :radio:checked');
var checked = $('#table :radio:checked');
扛起拖把扫天下 2024-09-09 01:54:19
$("table tr input[type=radio]:checked");
$("table tr input[type=radio]:checked");
忆依然 2024-09-09 01:54:19
//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();
//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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文