【发布时间】:2015-01-26 12:25:00
【问题描述】:
我有以下选择2:
<select id="e1" multiple style="width: 250px;" name="attributes[]">
<?php if(isset($vars['attributes'])):?>
<?php foreach($vars['attributes'] as $attribute):?>
<option value="<?php echo $attribute['id'];?>"><?php echo $attribute['name'];?></option>
<?php endforeach;?>
<?php endif;?>
</select>
现在我通过加载一些数据。阿贾克斯:
其中列出了以下数组:
现在我希望将这 3 个作为选定值添加到我的 select2 中。
我该怎么做?
更新
到目前为止,这是我的代码:
var _lst = document.getElementById('e1');
var optCount = _lst.options.length;
for (var i=0 ; i<data['attributes'].length; i++){
var opt = new Option(data['attributes'][i]['name'],data['attributes'][i]['id']);
_lst.options[optCount+i] = opt;
}
【问题讨论】:
标签: javascript select jquery-select2