在YII中使用jQuery的ESelect2扩展获取选项值和文本

时间:2018-01-23 06:08:51

标签: php jquery yii jquery-select2

Hello Friends这是我的代码

$this->widgets('ext.select.ESelect2', array(
    'model' => $model,
    'attribute' => 'state',
    'data' => $data,
    'htmloptions'=>array(
     'multiple'=>'multiple',
      ),
    'options' =>array(
        'placeholder' => 'Select a state ...',
        'allowClear'=> true,
         ), 
    ));

如何在jquery中获取选项值和文本。我想要选择所选选项的值。 请建议并帮助我。

1 个答案:

答案 0 :(得分:0)

您可以使用输入的类或ID来获取输入的值,请尝试以下方法:

$('#id_select_input').change(function() {
   var selected  = $(this).val(); 
   var textValue = $this.text();
});

希望这会对你有所帮助。

$this->widgets('ext.select.ESelect2', array(
'id'=>'id_select_input',
'model' => $model,
'attribute' => 'state',
'data' => $data,
'htmloptions'=>array(
 'multiple'=>'multiple',
  ),
'options' =>array(
    'placeholder' => 'Select a state ...',
    'allowClear'=> true,
     ), 
));