簡體   English   中英

jQuery啟用/禁用復選框

[英]Jquery Enable/Disable checkbox

當頁面具有一組以上的datepicker時,我試圖使此代碼正常工作。

如果您選擇選項“我目前在這里工作”,那么這會影響兩個組,而我只想影響當前的組。

我的密碼

$('.current-work-status').change(function () {
    $('.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);
});

更新的領域

嘗試

DEMO

使用jQuery .parents()選擇器查找組的父級,並使用.find()獲取.form-control-2和update屬性。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM