【发布时间】:2012-02-08 16:15:21
【问题描述】:
所以我有一个标准的选择下拉菜单。选择中的一个选项(最后一个)我有一个文本字符串 - var abc。
<select id="exampleselect">
<option>123</option>
<option>xyz</option>
<option>ABC</option>
</select>
var abc = "ABC";
我要做的是通过选择进行搜索,找到与 var abc 的匹配项,然后将 var abc 的匹配项更改为选定选项。
我尝试过的:
//gets all the options from the select
var selectoptions = $('#exampleselect').find('option').text();
//if there is a match of var abc to any of the options in the select
if (selectoptions == abc)
{
//work out how to get the index/eq of the matched element
//put matched element as selected value
$('#exampleselect').val(matchedelementindex);
}
【问题讨论】:
-
那么您希望最后一个选项是动态的吗?值将如何设置?
标签: javascript jquery drop-down-menu