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

时间:2016-09-30 12:12:14

标签: javascript php html yii1.x

我有这段代码:

<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];
    }

我无法开发负责显示/隐藏textField:

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

仅当用户按下其他&#39;按钮。(getData数组)。我该如何开发它?

1 个答案:

答案 0 :(得分:0)

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