<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
//写法1
//var ddl = document.getElementById("<%=ddlDept.ClientID %>");
//写法2
//var ddl=$("#<%=ddlDept.ClientID%>");
alert(ddl.selectedIndex);
}); function show(obj) {
var v = $(obj).val();
alert(v);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList runat="server" ID="ddlDept" onchange="show(this)" />
</div>
</form>
</body>
</html>

上面是前台代码,下面是后台代码.

  public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<string> list=new List<string>(){"aaa","bbb","ccc"};
ddlDept.DataSource = list;
ddlDept.DataBind();
ddlDept.SelectedIndex = ;
}
}

不知道用jQuery怎么写。

另一种版本的写法(全部在前台完成):

 <head runat="server">
<title></title>
<script type="text/javascript" language="javascript">
function SearchChange() {
var ddl = document.getElementById("DropDownList1")
var index = ddl.selectedIndex; var Value = ddl.options[index].value;
var Text = ddl.options[index].text; alert(Value);
alert(Text);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" onchange="SearchChange();">
<asp:ListItem Value="0">111</asp:ListItem>
<asp:ListItem Value="1">222</asp:ListItem>
<asp:ListItem Value="2">333</asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>

通过js获取DropDownList的选中项的更多相关文章

  1. 每日学习心得:Js获取Checkboxlist所选值、instanceof 和typeof区别、为Array添加contains方法

    2013-11-24 前言: 上周在工作中遇到了一些跟JS以及前台交互的问题,虽然算不上多么高深,但是在解决时也走了一些弯路,所以就总结一下. 1.    JS获取checkboxList所选的值 这 ...

  2. JS 获取select(多选下拉)中所选值的示例代码

    通过js获取select(多选下拉)中所选值,具体实现如下,有需要的朋友可以参考下,希望对大家有所帮助 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML ...

  3. js获取checkbox复选框获取选中的选项

    js获取checkbox复选框获取选中的选项 分享下javascript获取checkbox 复选框获取选中的选项的方法. 有关javascript 获取checkbox复选框的实例数不胜数.js实现 ...

  4. JS获取DropDownList选择项的值

    var dropDownList= document.getElementById("<%=DropDownListID.ClientID %>");//获取DropD ...

  5. JS获取Dropdownlist选中值

    var dropDownList = document.getElementById("ddl_sheng"); //获取DropDownList控件 var dropDownLi ...

  6. WPF学习笔记:获取ListBox的选中项

    有代码有J8: UI <UserControl x:Class="UnitViews.UserListUV" xmlns="http://schemas.micro ...

  7. 用JS获取DropDownList选中得值

    HTML: <asp:DropDownList ID="DropdownList1" runat="server" AutoPostBack=" ...

  8. js 获取单项复选的值

    html: 单选框-----> 25岁以下 25~35岁 35~50岁 50岁以上 获值 var question1 = $('input:radio[name="radio" ...

  9. JS获取页面复选框选中的值

    function jqchk(){ //jquery获取复选框值 var chk_value =[]; $('input[class="sel"]:checked').each(f ...

随机推荐

  1. SQL Server之内连接 左连接 右连接 全连接 交叉连接

    SELECT * FROM Table_A GO SELECT * FROM Table_B GO --内连接 SELECT a.*, b.* FROM Table_A a JOIN Table_B ...

  2. VMware系统运维(十四)部署虚拟化桌面 Horzion View Manager 5.2 配置许可

    1.通过网页访问https://conntionserver.testad.local/admin,打开如下图所示页面:输入用户名密码 2.进来以后配置View 许可,点击"编辑许可证&qu ...

  3. DNS resolving 占用大量日志

    公司内部DNS配置好后,测试解析正常,只是几乎每秒都有无法解析的日志产生.但分析日志时发现,每天的日志都有2G左右.日志中几乎全是类似network unreachable resolving 'ww ...

  4. 第五节 关于SpringMVC中Ajax的配置和应用[下午]

    成熟,不是学会表达,而是学会咽下,当你一点一点学会克制住很多东西,才能驾驭好人生. 还有一周,祥云19就算结算了,一个半月的相处希望,胖先生算一个合格的老师 小白,小蔡,2婷婷,小猴,小恒,小崔,小龙 ...

  5. How To Install Development Tools In Linux

      In this brief tutorial, we will be discussing how to install development tools in popular Linux di ...

  6. LinearLayout和RelativeLayout

    LinearLayout和RelativeLayout 共有属性:java代码中通过btn1关联次控件android:id="@+id/btn1" 控件宽度android:layo ...

  7. 二十、Android -- SDcard文件读取和保存

    背景                                                                                            一些东西可以 ...

  8. au3 命令

    Case $Button1                        _RunDOS(@SystemDir &"\sysdm.cpl");打开系统属性          ...

  9. C#如何关闭一个窗口的同时打开另一个窗口

    在.net的WinForm程序中,如果是直接起动的Form作为主窗口,那么这个主窗口是不能关闭的,因为它维护了一个Windows消息循环,它一旦关闭了就等于声明整个应用程序结束,所以新打开的窗口也就被 ...

  10. VHDL MOD和REM(转)

    mod(取模)and rem(取余) VHDL has mod and rem. They return the same value if both arguments are positive. ...