Javascript 如何使用yii2下拉列表隐藏块

Javascript 如何使用yii2下拉列表隐藏块,javascript,yii2,Javascript,Yii2,我在Yii2项目中有dropDownList <?= $form->field($model, 'license', ['options' =>['onchange'=>'getSalutationValue()'] )->dropDownList(['y' => 'Yes', 'n' => 'No']) ?> 我做错了什么?请帮助我您没有传递输入字段的对象,以便您可以使用其值, 试试这个 更新: <?= $form->field(

我在Yii2项目中有dropDownList

<?= $form->field($model, 'license', ['options' =>['onchange'=>'getSalutationValue()'] )->dropDownList(['y' => 'Yes', 'n' => 'No']) ?>

我做错了什么?请帮助我

您没有传递输入字段的对象,以便您可以使用其值, 试试这个

更新:

 <?= $form->field($model, 'license')->dropDownList(['y' => 'Yes', 'n' => 'No'],['onchange'=>'getSalutationValue(this)']) ?>


它不起作用,我认为dropdownList值未传递您的语法错误,甚至我忘记查看。检查更新的答案。
 <?= $form->field($model, 'license', ['options' =>['onchange'=>'getSalutationValue(this)'] )->dropDownList(['y' => 'Yes', 'n' => 'No']) ?>
 function getSalutationValue(obj) {
    var label = obj.value;
    if(label == 'n' ) {
    document.getElementById('driver').style.display='none';
        }}
 <?= $form->field($model, 'license')->dropDownList(['y' => 'Yes', 'n' => 'No'],['onchange'=>'getSalutationValue(this)']) ?>