我想在选中相应的 chkView 时启用该行的编辑和删除复选框,如果未选中则禁用它们。这段代码一开始根本就没有触发。我哪里错了。
http://jsfiddle.net/75rVH/1/
HTML
<table id="table_forms">
<tr>
<td><input type="checkbox" class="chkView"/>View</td>
<td><input type="checkbox" class="chkEdit" disabled/>Edit</td>
<td><input type="checkbox" class="chkDelete" disabled/>Delete</td>
</tr>
<tr>
<td><input type="checkbox" class="chkView"/>View</td>
<td><input type="checkbox" class="chkEdit" disabled/>Edit</td>
<td><input type="checkbox" class="chkDelete" disabled/>Delete</td>
</tr>
</table>
JS:
$(document).on('change','.chkView',function(){
var row = $(this).closest('tr');
if($(this).prop("checked",true))
{
$(row).find('.chkEdit').prop("disabled",false);
$(row).find('.chkDelete').prop("disabled",false);
}
else
{
$(row).find('.chkEdit').prop("disabled",true);
$(row).find('.chkDelete').prop("disabled",true);
}
});
尝试这个:
$(document).on('change', '.chkView', function() {
$(this).closest('tr').find('.chkEdit, .chkDelete').prop('disabled', !this.checked);
});
Demo: http://jsfiddle.net/75rVH/3/
另外为了保持一致性,如果有可能的话.chkView
加载已经检查,您需要确保触发它们的更改事件以使相应的编辑和删除行为正常$('.chkView:checked').change();
(demo).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)