【发布时间】:2011-02-20 13:51:13
【问题描述】:
我有一个包含 n 行的 HTML 表格,每行在 Row.Using 中包含一个单选按钮。使用 jQuery,我如何查看这些单选按钮来检查哪个单选按钮被选中?
【问题讨论】:
标签: jquery radio-button
我有一个包含 n 行的 HTML 表格,每行在 Row.Using 中包含一个单选按钮。使用 jQuery,我如何查看这些单选按钮来检查哪个单选按钮被选中?
【问题讨论】:
标签: jquery radio-button
【讨论】:
<tbody>,我会给予 +1。
要遍历所有选中的单选按钮,您也可以这样做:
$('input:radio:checked').each(function() {
//this loops through all checked radio buttons
//you can use the radio button using $(this)
});
【讨论】:
//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();
【讨论】:
var checked = $('#table :radio:checked');
【讨论】:
$("table tr input[type=radio]:checked");
【讨论】:
$('.my-radio-class:checked')
【讨论】:
$('#table tbody tr input[type=radio]').each(function(){
alert($(this).attr('checked'));
});
HTH。
【讨论】:
#table > tr 会在喜欢添加自己的tbody 元素的某些浏览器(chrome/firefox)上阻塞,而#table tr 不会。