[英]How to show/hide an element on checkbox checked/unchecked states using jQuery
I have this code: 我有以下代码:
<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 retrieve elements of checkbox: this code is getData code: getData检索复选框的元素:此代码为getData代码:
$data = array(
'b_category' => array(
'1',
'2',
'3',
'other'
),
);
return $data[$property];
}
I could not develop js file that responsible for showing/hiding following textField: 我无法开发负责显示/隐藏以下textField的js文件:
<?= $form->textField($model, 'p_16_13', array(
'class' => 'form-control dotted', 'placeholder' => Yii::t('subscription', 'указать другой вид деятельностит'))) ?>
only when user presses 'other' button.(getData array). 仅当用户按下“其他”按钮时。(getData数组)。 How can i develop it? 我该如何开发?
$(selector).on('change', function(){
if($(this).is(':checked')){
// checkbox is checked
} else {
// here is not
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.