繁体   English   中英

依赖下拉列表在yii2中不起作用

[英]Dependent dropdown is not work in yii2

如何在select2下拉列表kartik中添加ID。 当我在下拉列表中选择值“成功”时我想要的目标,因此在另一个下拉列表example2和example3中禁用的值是false。 在此之前,对于下拉列表example2和example3,其值为“ yes”为false。 我已经创建了JavaScript代码,但无法正常工作。 我不知道,请告诉我。

这是我的代码:

 <?php echo $form->field($model, 'example')->widget(Select2::classname(), [ 'model' => $model, 'hideSearch' => true, 'data' => ['success' => 'Success', 'fail' => "Fail"], 'language' => 'id', 'options' => [ 'placeholder' => 'Pilih', 'options' => [ ['id' => 'example'], ] ], 'pluginOptions' => [ 'allowClear' => true, 'width' => '350px', ], ])->label('Example'); ?> <?php echo $form->field($model, 'example2')->widget(Select2::classname(), [ 'model' => $model, 'hideSearch' => true, 'data' => ['yes' => "Yes", 'no' => "No"], 'language' => 'id', 'options' => [ 'placeholder' => 'Pilih', 'options' => [ 'yes' => ['disabled' => true], ['id' => 'example2'], ] ], 'pluginOptions' => [ 'allowClear' => true, 'width' => '350px', ], ])->label('Example 2'); ?> <?php echo $form->field($model, 'example3')->widget(Select2::classname(), [ 'model' => $model, 'hideSearch' => true, 'data' => ['yes' => "Yes", 'no' => "No"], 'language' => 'id', 'options' => [ 'placeholder' => 'Pilih', 'options' => [ 'yes' => ['disabled' => true], ['id' => 'example3'], ] ], 'pluginOptions' => [ 'allowClear' => true, 'width' => '350px', ], ])->label('Example 3'); ?> 

此javascript代码:

 <?php $this->registerJs(' $("input[type=dropdown]").change(function() { var isi = this.value; if(isi == "success") { $("#example2").attr("disabled",false); $("#example3").attr("disabled",false); } }); ') ?> 

可能这就是您想要的。 为第一个选择元素添加选项(#example):

'pluginEvents' => [
        "change" => "function() { 
            var value = $(this).val();
            if(value == 'success') 
            {
                $('#demo-example2').val('yes');
                $('#demo-example2').trigger('change');
                $('#demo-example3').val('yes');
                $('#demo-example3').trigger('change');
            }
        }",    
    ]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM