Javascript Yii2-如何在activeform中添加onchange事件

Javascript Yii2-如何在activeform中添加onchange事件,javascript,yii2,Javascript,Yii2,这是我的代码: <?= $form->field($model, 'int_roomCatId') ->dropDownList(ArrayHelper::map(TblCategory::find()->all(), 'int_category_id', 'str_category'), array('class' =>'form-control','prompt'=>'Select Room Category'))

这是我的代码:

<?= $form->field($model, 'int_roomCatId')
          ->dropDownList(ArrayHelper::map(TblCategory::find()->all(), 'int_category_id', 'str_category'), array('class' =>'form-control','prompt'=>'Select Room Category'))
          ->label('Room Category');  ?>


我想添加onchange=“getData()”事件。在哪里添加这个?

htmloptions
数组中,只需执行以下操作:

dropDownList(ArrayHelper::map(TblCategory::find()->all(), 'int_category_id', 'str_category'), array('onchange'=>'getData()','class' =>'form-control','prompt'=>'Select Room Category'))
htmloptions
数组中的每个键和值都将转换为html属性,例如:

'key'=>'value'
将显示为:

<tag key="value" /> 

您可以使用以下命令调用:

<?= $form->field($model, 'product_name')->dropDownList(ArrayHelper::map(Products::find()->all(), 'id', 'name'), 
             ['prompt'=>'-Choose a Product-',
              'onchange'=>'
                $.get( "index.php?r=suborders/listprice&id="+$(this).val(), function( data ) {
                  $( "#suborders-product_price" ).val( data );
                });
            ']);
    ?>

希望这对您有所帮助。

以下是我是如何做到的:

    echo $form->field($flightSearchForm, "lastDepartTimeChange", 
        ['options' => ['class' => 'col-xs-12', 
                       'onchange' => "changeHidden(\"departFlightTimeMin\")"]
         ])->widget(\yii\jui\SliderInput::classname());
如您所见,我只是将其放在HTML选项数组中,这是$form->field函数的第三个输入。希望这有帮助