Jquery Enable/Disable 复选框

Jquery Enable/Disable checkbox

当页面有超过 1 组日期选择器时,我试图让这段代码工作。

如果您 select 选项 "I currently work here" 它会影响两个组,而我只想影响当前组。

My code

$('.current-work-status').change(function () {
    $('.form-control-2').prop('disabled', $(this).is(':checked'));
});

尝试

DEMO

使用 jQuery .parents() selector to find parent of group and using .find() 获取 .form-control-2 并更新属性。

$('.current-work-status').change(function () {
   $(this).parents('div.row').find('.form-control-2').prop('disabled', $(this).is(':checked'));
});

尝试

$('.current-work-status').change(function () {
    $(this).closest('div').prev().find('.form-control-2').prop('disabled', this.checked);
});

updated fidle