如何使用jQuery显示/隐藏复选框中选中/未选中状态的元素


How to show/hide an element on checkbox checked/unchecked states using jQuery

我有这样的代码:

<div class="form-group">
                        <?= $form->labelEx($model, 'd_options', array('class' => 'col-xs-12 col-sm-4 control-label')) ?>
                        <div class="col-xs-12 col-sm-8" id="d_options_element">
                            <?= $form->checkBoxList($model, 'd_options', $model->getData('d_options'), array(
                                'template' => '<div  class="checkbox col-xs-12 col-sm-4">{beginLabel}{input}{label}{endLabel}</div>',
                                'separator' => '',
                            )); ?>
                            <div class="col-xs-12 col-sm-8 p_16_13" id="d-parts"
                                 style="<?= (in_array(12, $model->d_options)) ? '' : 'display: none;' ?>">
                                <?= $form->textField($model, 'p_16_13', array(
                                    'class' => 'form-control dotted', 'placeholder' => Yii::t('subscription', 'указать другой вид деятельностит'))) ?>
                                <?= $form->error($model, 'p_16_13') ?>
                            </div>
                            <?= $form->error($model, 'p_16') ?>
                        </div>
                    </div>

getData检索复选框的元素:这个代码是getData代码:

 $data = array(
            'b_category' => array(
               '1', 
               '2',
               '3',
               'other'   
                      ),
);
        return $data[$property];
    }

我无法开发js文件,负责显示/隐藏以下textField:

<?= $form->textField($model, 'p_16_13', array(
                                    'class' => 'form-control dotted', 'placeholder' => Yii::t('subscription', 'указать другой вид деятельностит'))) ?>

仅当用户按下"其他"按钮时。(getData数组)。我怎样才能培养它?

$(selector).on('change', function(){
    if($(this).is(':checked')){
        // checkbox is checked
    } else {
        // here is not
    }
});