<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. ubuntu16.04 编译安装mysql5.7.x,以及配置使用

    編譯與安裝: 源码下载地址:http://dev.mysql.com/downloads/mysql/    选择Generic Linux (Architecture Independent), C ...

  2. 重构8-Replace Inheritance with Delegation(委托替换继承)

    继承的误用十分普遍.它只能用于逻辑环境,但却经常用于简化,这导致复杂的没有意义的继承层次.看下面的代码: public class Sanitation{ public String WashHand ...

  3. Oracle基础 exp/imp 数据泵导入/导出 命令

    一.导出方式: 使用exp/imp方式导出数据分为四种方式: 1.表方式导出:一个或多个指定的表,包括表的定义.表数据.表的所有者授权.表索引.表约束,以及创建在该表上的触发器.也可以只导出结构,不导 ...

  4. netbeans 调试 php

    修改php.ini文件 原来配置 [XDebug];zend_extension = "E:\xampp\php\ext\php_xdebug.dll";xdebug.profil ...

  5. VMware系统运维(十六)部署虚拟化桌面 Horizon View Manager 5.2 配置池

    1.点击"添加",打开添加池界面,选择"自动池",点击"下一步" 2.选择"专用,启动自动分配",点击"下一步 ...

  6. JavaScript中的getBoundingClientRect()方法

    这个方法返回一个矩形对象,包含四个属性:left.top.right和bottom.分别表示元素各边与页面上边和左边的距离. getBoundClientRect()方法返回的对象中和CSS中所定义不 ...

  7. jquery实现简单的ajax

    -->html页 1: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "htt ...

  8. 五.CSS盒子模型

    所谓盒模型,就是浏览器为每个HTML元素生成的矩形盒子.即HTML页面实际上就是由一系列盒子组成.这些盒子是按照可见版式在页面上排布的.并由三个属性进行控制:position属性,display属性, ...

  9. iOS 通过tag查找控件

    //比如创建一个UIImageView到view上 UIImageView *imageView = [[UIImageView allc] init]; imageView.tag = 10001; ...

  10. Part 6 AngularJS ng repeat directive

    ng-repeat is similar to foreach loop in C#. Let us understand this with an example. Here is what we ...