这些解决方案似乎假设下拉列表中的每个项目都有一个与其在下拉列表中的位置相关的val()值。
如果不是这种情况,事情会稍微复杂一些。
要读取下拉列表的选定索引,您可以使用:
$("#dropDownList").prop("selectedIndex");
要设置下拉列表的选定索引,您可以使用:
$("#dropDownList").prop("selectedIndex", 1);
请注意,prop()功能需要 JQuery v1.6 或更高版本。
让我们看看您将如何使用这两个函数。
假设您有一个月份名称的下拉列表。
<select id="listOfMonths">
  <option id="JAN">January</option>
  <option id="FEB">February</option>
  <option id="MAR">March</option>
</select>
您可以添加“上个月”和“下个月”按钮,该按钮查看当前选择的下拉列表项,并将其更改为上/下个月:
<button id="btnPrevMonth" title="Prev" onclick="btnPrevMonth_Click();return false;" />
<button id="btnNextMonth" title="Next" onclick="btnNextMonth_Click();return false;" />
这是这些按钮将运行的 JavaScript:
function btnPrevMonth_Click() {
    var selectedIndex = $("#listOfMonths").prop("selectedIndex");
    if (selectedIndex > 0) {
        $("#listOfMonths").prop("selectedIndex", selectedIndex - 1);
    }
}
function btnNextMonth_Click() {
    //  Note:  the JQuery "prop" function requires JQuery v1.6 or later
    var selectedIndex = $("#listOfMonths").prop("selectedIndex");
    var itemsInDropDownList = $("#listOfMonths option").length;
    //  If we're not already selecting the last item in the drop down list, then increment the SelectedIndex
    if (selectedIndex < (itemsInDropDownList - 1)) {
        $("#listOfMonths").prop("selectedIndex", selectedIndex + 1);
    }
}
我的站点对于展示如何使用 JSON 数据填充下拉列表也很有用:
http://mikesknowledgebase.com/pages/Services/WebServices-Page8.htm