如何使这项工作?当取消选中Bar时,其他输入复选框在每个td中删除禁用?我是Jquery的初学者:)
原始代码取自 Original code
<table border="1" id="re">
<tr>
<td class="class1"><input type=checkbox disabled="disabled" value="ss"/>ss</td>
<td class="class1"><input type=checkbox disabled="disabled" value="aa"/>aa</td>
<td class="class1"><input type=checkbox disabled="disabled" value="dd"/>dd</td><td class="class1"><input type=checkbox checked="checked" value="bar"/>Bar</td></tr>
<tr>
<td class="class1">
<input type=checkbox disabled="disabled" value="ss"/>ss</td><td class="class1">
<input type=checkbox disabled="disabled" value="aa"/>aa</td><td class="class1">
<input type=checkbox disabled="disabled" value="dd"/>dd</td><td class="class1">
<input type=checkbox checked="checked" value="bar"/>Bar
</td></tr>
<tr>
<td class="class1">
<input type=checkbox disabled="disabled" value="ss"/>ss</td><td class="class1">
<input type=checkbox disabled="disabled" value="aa"/>aa</td><td class="class1">
<input type=checkbox disabled="disabled" value="dd"/>dd</td><td class="class1">
<input type=checkbox checked="checked" value="bar"/>Bar
</td></tr>
</table>
$('.class1 input:last-of-type').live('change', function () {
var n = $(this).siblings('input:checkbox');
if (!$(this).attr('checked')) {
n.attr('disabled',false);
} else {
n.attr('disabled', true);
}
});
答案 0 :(得分:2)
尝试类似
的内容$('table').on('click', 'input[value="bar"]', function(e){
var $this = $(this);
var checked = $this.is(':checked');
var others = $this.closest('tr').find('input:checkbox').not(this).prop('disabled', checked)
if(checked){
others.prop('checked', false);
}
})
演示:Fiddle