0

我想要一个在 html 表中搜索的 javascript 或 jquery 函数,如果没有选择收音机,则通知用户。我只有表 id,不知道收音机 id。

4

3 回答 3

3

演示

在代码中,您可以替换table为,#tableID以便代码仅针对该表运行

$(document).ready(function () {
    if ($('table input[type=radio]:checked').length < 1) {
        alert('No Radio Button Selected');
    }
});

如果你想table点击通知

 $('table').click(function () {
        if ($('table input[type=radio]:checked').length < 1) {
            alert('No Radio Button Selected');
        }
    });
于 2013-07-31T13:58:01.550 回答
0

您可以使用is()which 返回一个布尔值:

if (!$('table :radio').is(':checked')) {
        alert('No Radio Button Selected');
    }

如果至少选中一个单选按钮,则不会触发 alert()

于 2013-07-31T14:08:16.413 回答
0
$('#table input:radio:checked') will give the radios checked inside table with id `#table`
于 2013-07-31T13:58:22.740 回答