无法选择表格前三行中的所有单选按钮

Posted

技术标签:

【中文标题】无法选择表格前三行中的所有单选按钮【英文标题】:Unable to select all radio buttons in first three rows of a table 【发布时间】:2014-08-27 23:33:10 【问题描述】:

我有一张表格,其中每一行都有大约 11 个单选框和一些其他属性。 我想让前 3 行的单选按钮不可编辑,并使用下面的代码。请说明为什么它不起作用。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function()
$('tr:lt(2) input[type=radio]').prop('readOnly',true);
);
</script>

【问题讨论】:

你也可以发布 html 吗? Disabling radio buttons with jQuery 的可能重复项 【参考方案1】:

你需要使用 prop disabled 作为true:

$('tr:lt(2) input[type=radio]').prop('disabled',true);

【讨论】:

只读在单选按钮中不起作用。请参阅此答案以解决***.com/questions/1953017/…【参考方案2】:

以上代码均无效,请查看下面的示例 html 并提出建议。

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function()
$('tr:lt(3)').find('input[type=radio]').prop('readonly',true);
);
</script>
</head>
<body>
<table border='1'>

<tr>
<td>Test1</td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
</tr>

<tr>
<td>Test2</td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
</tr>

<tr>
<td>Test3</td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
</tr>

<tr>
<td>Test4</td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
</tr>

<tr>
<td>Test5</td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
</tr>

<tr>
<td>Test6</td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
<td><input type="radio"></td>
</tr>

</table>
</body>
</html>

【讨论】:

以上是关于无法选择表格前三行中的所有单选按钮的主要内容,如果未能解决你的问题,请参考以下文章

离子单选按钮验证

UITableview 内的单选按钮不起作用

如何删除表格视图单元格中单选按钮的索引路径?

jQuery选择器如何选择页面中的所有单选按钮和多选按钮?

DW里面在表格里加表单,单选按钮的问题

如何在表格视图中一次选择单选按钮