使用JQuery获取下拉列表选择的值 [英] Get Dropdown selected value using JQuery

查看:102
本文介绍了使用JQuery获取下拉列表选择的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码通过JQuery获取下拉菜单的选定值.

I use the following code to get the selected value of my dropdown using JQuery.

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

但是我得到的结果是undefined.我想念什么?

But I get the result as undefined. What am I missing?

我的下拉菜单的HTML:

The HTML for my dropdown:

<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:

id attributes of ASP.Net controls are generated server-side, so in your generated HTML, the id would actually be something like _$ctrl0239023930. What you need to use is ClientID like this:

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

这篇关于使用JQuery获取下拉列表选择的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆