首页 新闻 会员 周边

multiple select 赋值

0
悬赏园豆:20 [待解决问题]

  

<select id="recipient-select" class="chosen-select" multiple="multiple">
<option>Aeróbics</option>
<option>Aeróbics en Agua</option>
<option>Aerografía</option>
<option>Aeromodelaje</option>
</select>

如何给上边的select 赋值  不是添加<option></option>

 

 

^cherish~的主页 ^cherish~ | 初学一级 | 园豆:189
提问于:2014-08-01 09:47
< >
分享
所有回答(2)
0

$("#recipient-select").val("Aeróbics en Agua");

刘宏玺 | 园豆:14020 (专家六级) | 2014-08-01 10:24
0

一:javascript方法

1:拿到select对象: var myselect=document.getElementById("recipient-select");
2:拿到选中项的索引:var index=myselect.selectedIndex ; //
selectedIndex代表的是你所选中项的index
3:拿到选中项options的value:
myselect.options[index].value;
4:拿到选中项options的text:
myselect.options[index].text;

二:jquery方法
1:var options=$("#test option:selected"); //获取选中的项
2:alert(options.val()); //拿到选中项的值
3:alert(options.text()); //拿到选中项的文本

逗号s | 园豆:4 (初学一级) | 2014-08-01 16:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册