Jquery 无法在另一次冲压单选按钮后禁用单选按钮
我有一个单选按钮和一个包含许多单选按钮的表格。我正在按页面加载上的单选按钮 然后根据条件禁用表中每一行的第一个单选按钮。下面是我正在使用的代码,但是,无论是单选按钮正在冲压,还是其他按钮正在禁用Jquery 无法在另一次冲压单选按钮后禁用单选按钮,jquery,Jquery,我有一个单选按钮和一个包含许多单选按钮的表格。我正在按页面加载上的单选按钮 然后根据条件禁用表中每一行的第一个单选按钮。下面是我正在使用的代码,但是,无论是单选按钮正在冲压,还是其他按钮正在禁用 <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script> $(docu
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function
$("#Q6x1_8").prop('checked',true);
if($("#Q6x1_8").is(':checked'))
$('tr td').find('input[type=radio']).first().prop('disabled',true);
});
</script>
</head>
<body>
<input type='radio' id='Q6x1_8'>Click<p>
<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>
$(文档).ready(函数)
$(“#Q6x1_8”).prop('checked',true);
如果($(“#Q6x1_8”)是(':选中的'))
$('tr td').find('input[type=radio']).first().prop('disabled',true);
});
点击
测试1
测试2
测试3
测试4
测试5
测试6
$(文档)。准备就绪(函数应为
$(文档).ready(函数(){
- 如果条件始终为真,则不会使用
$(document).ready(function () {
$("#Q6x1_8").prop('checked', true);
$('tr').each(function () {
$(':radio:first',this).prop('disabled', true);
});
});
这样做您将需要这样一个循环: js
$("#Q6x1_8").prop('checked',true);
$("table tr").each(function(){
if($("#Q6x1_8").is(':checked'))
$(this).find('input[type="radio"]').first().prop('disabled',true);
});
或者,如果选中或未选中复选框,您可以使用复选框启用/禁用无线电
:
$("#Q6x1_8").on("change", function(){
$("table tr").each(function(){
if($("#Q6x1_8").is(':checked'))
$(this).find('input[type="radio"]').first().prop('disabled',true);
else
$(this).find('input[type="radio"]').first().prop('disabled',false);
});
});
如果我理解正确
$(document).ready(function () {
$("#Q6x1_8").prop('checked', true);
if($("#Q6x1_8").is(':checked')) {
$('tr td:nth-child(2)').children('input[type="radio"]').attr('disabled', true);
}
});
使用第n个子元素选择元素
$('tr td:nth-child(2) :radio').prop('disabled', true);
你为什么要在中打孔?勾选/取消勾选它们你是否试图在页面加载时将收音机设置为选中状态…?你为什么不能在html
中设置它?那么一旦勾选了,你打算如何取消勾选它…$(文档)。就绪(函数
应该是$(文档)。就绪(函数(){
@ShaunakD我必须在一个工具中使用它..为了展示演示,我使用jquery检查它,我的目的是检查单选按钮是否被选中,如果是,然后禁用每行的第一个单选按钮。谢谢它对我有效,但我想禁用每行的第一个单选按钮。谢谢,还有其他短方法代替l吗oop?是的。看看@Tilwin Joy的答案。谢谢@Tilwin Joy,它对我很有用,你能告诉我“children”的用法吗?它会指每个td的第二个元素吗?不,我只是想补充一下,find()
将只搜索直接儿童(重量轻),因为我们知道收音机是
的直接儿童,所以最好使用儿童进行表演…非常感谢:)@Tilwin
$('tr td:nth-child(2) :radio').prop('disabled', true);