繁体   English   中英

Yii2向dropdownlist表单字段添加类或函数

[英]Yii2 add class or function to dropdownlist form field

我需要在Yii2 activeform的下拉列表中添加一个类和一个函数,这里是代码:

 <?= $form->field($model, 'tipocontratto')->dropDownList(['RES' => 'Residenziale', 'BUS' => 'Business'], ['prompt'=>'Seleziona...'],['maxlenght'=> true]); ?> 

我需要为字段指定一个类,还需要一个javascript函数。 在正常的文本字段中,我这样做: field($model, 'cogn_ragsoc')->textInput(['maxlength' => true,'class'=>'form-control formtesto','onfocus'=>'test()']) ?> andd它运行完美,但在下拉列表中它不是我怎么办?

这非常有效。

<?= $form->field($model, 'tipocontratto')->dropDownList(['RES' => 'Residenziale', 'BUS' => 'Business'], ['prompt'=>'Seleziona...','class'=>'yourclass','onchange'=>'function()']); ?>

尝试用类添加选项,例如::

<?= $form->field($model, 'tipocontratto')->dropDownList(['RES' => 'Residenziale', 'BUS' => 'Business'], 
['prompt'=>'Seleziona...'],['maxlenght'=> true], 
[options=> ['class' => 'yuorClass']]); ?>

暂无
暂无

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

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