使用jquery在按钮单击时选择一个下拉选项
问题描述:
我想用jQuery通过点击一个按钮来选择一个选项,比如说第3项,在DropDownList中,然后让DropDownList框改变它的值,比如'44'。
I want to use jQuery to select an option, say the 3th item, in a DropDownList by clicking a button, then have the DropDownList box change it's value, say '44'.
<asp:DropDownList ID="DropDownList2" runat="server"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem Selected="True">SELECT</asp:ListItem>
<asp:ListItem Value="1">23</asp:ListItem>
<asp:ListItem Value="2">32</asp:ListItem>
<asp:ListItem Value="3">44</asp:ListItem>
<asp:ListItem Value="4">61</asp:ListItem>
</asp:DropDownList>
答
这可能会帮助您
var dropDownList2ID = "#<%=DropDownList2.ClientID%>";
var buttonID = "#idOfButton";
//...
$(buttonID).click(function() {
$(dropDownList2ID).val(3);
});