gpt4 book ai didi

jquery - 使用 JQuery 获取 Dropdown 选定值

转载 作者:行者123 更新时间:2023-12-03 22:13:51 25 4
gpt4 key购买 nike

我使用以下代码通过 JQuery 获取下拉列表的选定值。

pStartMonth = $('#cboMonth1').val();

但我得到的结果是未定义。我错过了什么?

我的下拉菜单的 HTML:

<asp:DropDownList ID="cboMonth1" runat="server" AutoPostBack="true" onclick="javascript:shouldsubmit=false;" ValidationGroup="vTimeSlot">
<asp:ListItem Value="0">-Select-</asp:ListItem>
<asp:ListItem Value="1">January</asp:ListItem>
<asp:ListItem Value="2">February</asp:ListItem>
<asp:ListItem Value="3">March</asp:ListItem>
<asp:ListItem Value="4">April</asp:ListItem>
<asp:ListItem Value="5">May</asp:ListItem>
<asp:ListItem Value="6">June</asp:ListItem>
<asp:ListItem Value="7">July</asp:ListItem>
<asp:ListItem Value="8">August</asp:ListItem>
<asp:ListItem Value="9">September</asp:ListItem>
<asp:ListItem Value="10">October</asp:ListItem>
<asp:ListItem Value="11">November</asp:ListItem>
<asp:ListItem Value="12">December</asp:ListItem>
</asp:DropDownList>

最佳答案

ASP.Net 控件的

id 属性是在服务器端生成的,因此在生成的 HTML 中,id 实际上类似于 _$ctrl0239023930。您需要使用的是ClientID,如下所示:

pStartMonth = $('#<%= cboMonth1.ClientID %>').val();

关于jquery - 使用 JQuery 获取 Dropdown 选定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19243368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com