【问题标题】:How to show/hide an element on checkbox checked/unchecked states using jQuery如何使用jQuery显示/隐藏复选框选中/未选中状态的元素
【发布时间】:2016-09-30 12:12:13
【问题描述】:

我有这个代码:

<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 文件:

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

仅当用户按下“其他”按钮时。(getData 数组)。我该如何开发它?

【问题讨论】:

    标签: javascript php html yii1.x


    【解决方案1】:
    $(selector).on('change', function(){
        if($(this).is(':checked')){
            // checkbox is checked
        } else {
            // here is not
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-16
      • 2013-01-23
      • 1970-01-01
      • 1970-01-01
      • 2017-02-04
      • 1970-01-01
      • 1970-01-01
      • 2013-03-23
      相关资源
      最近更新 更多