php Yii2 下拉列表 onchange

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23227498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:35:17  来源:igfitidea点击:

Yii2 dropdownlist onchange

phpyii2

提问by Alex

In Yii 1 i could set onchange event for dropDownList by this method:

在 Yii 1 中,我可以通过以下方法为 dropDownList 设置 onchange 事件:

CHtml::dropDownList('id', $select, $list, array('onchange'=>'this.form.submit()'))

And it was pretty good. But in Yii 2 it doesn't work, how do i solve this issue?

它非常好。但是在 Yii 2 中它不起作用,我该如何解决这个问题?

回答by user1852788

this code submits on change properly:

此代码正确提交更改:

<?php use yii\helpers\Html; ?>
  <?= Html::beginForm() ?>
  <?= Html::dropDownList(
    'test', //name
    'b',  //select
    ['a'=>'A', 'b'=>'B'], //items
    ['onchange'=>'this.form.submit()'] //options
  )?>
  <?= Html::endForm() ?>