Yii2 主动形式
<?= $form->field($model, 'pid')->dropDownList([1=>1,2=>2])->hint('????') ?>
Run Code Online (Sandbox Code Playgroud)
我想禁用选项 2=>2。
有没有办法做到这一点?
您可以使用“选项”键为下拉列表中的所有项目添加属性。假设您要禁用第二项。
<?= $form->field($model, 'pid')->dropDownList([1 => 1, 2 => 2], ['options' => [2 => ['disabled' => true]]])->hint('????') ?>
Run Code Online (Sandbox Code Playgroud)
在文档中:http ://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#activeDropDownList() -detail