通过js获取DropDownList的选中项
<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的选中项的更多相关文章
- 每日学习心得:Js获取Checkboxlist所选值、instanceof 和typeof区别、为Array添加contains方法
2013-11-24 前言: 上周在工作中遇到了一些跟JS以及前台交互的问题,虽然算不上多么高深,但是在解决时也走了一些弯路,所以就总结一下. 1. JS获取checkboxList所选的值 这 ...
- JS 获取select(多选下拉)中所选值的示例代码
通过js获取select(多选下拉)中所选值,具体实现如下,有需要的朋友可以参考下,希望对大家有所帮助 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML ...
- js获取checkbox复选框获取选中的选项
js获取checkbox复选框获取选中的选项 分享下javascript获取checkbox 复选框获取选中的选项的方法. 有关javascript 获取checkbox复选框的实例数不胜数.js实现 ...
- JS获取DropDownList选择项的值
var dropDownList= document.getElementById("<%=DropDownListID.ClientID %>");//获取DropD ...
- JS获取Dropdownlist选中值
var dropDownList = document.getElementById("ddl_sheng"); //获取DropDownList控件 var dropDownLi ...
- WPF学习笔记:获取ListBox的选中项
有代码有J8: UI <UserControl x:Class="UnitViews.UserListUV" xmlns="http://schemas.micro ...
- 用JS获取DropDownList选中得值
HTML: <asp:DropDownList ID="DropdownList1" runat="server" AutoPostBack=" ...
- js 获取单项复选的值
html: 单选框-----> 25岁以下 25~35岁 35~50岁 50岁以上 获值 var question1 = $('input:radio[name="radio" ...
- JS获取页面复选框选中的值
function jqchk(){ //jquery获取复选框值 var chk_value =[]; $('input[class="sel"]:checked').each(f ...
随机推荐
- GCD调度组、自定义队列来实现多个下载任务
#define KURL1 @"http://img0.imgtn.bdimg.com/it/u=79920747,2237302485&fm=90&gp=0.jpg&quo ...
- oc中的block
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
- 《算法导论》习题解答 Chapter 22.1-2(邻接矩阵与链表)
链表如图: 矩阵: 1 2 3 4 5 6 7 1 0 1 1 0 0 0 0 2 1 0 0 1 1 0 0 3 1 0 0 0 0 1 1 4 0 1 0 0 0 0 0 5 0 1 0 0 0 ...
- vs克隆新建团队项目
团队资源——克隆,完成后打开: 在解决方案资源中,添加——新建项目——web——ASP.NET web应用程序——空的,并将其设为启动项目:
- 正则转nfa:完成
太累了,感觉不会再爱了.问题已经解决,具体的懒得说了. #include "regular_preprocess.h" //这个版本终于要上nfa了,好兴奋啊 //由于连个节点之间 ...
- CF 118E Bertown roads 桥
118E Bertown roads 题目:把无向图指定边的方向,使得原图变成有向图,问能否任意两点之间互达 分析:显然如果没有桥的话,存在满足题意的方案.输出答案时任意从一个点出发遍历一遍即可. 求 ...
- Application Loader上传app时报错:the bundle identifier cannot be changed from the current value
报错如图: 解决:用info.plist中的bundle identifier生成发布证书(Distribution),如图:
- BZOJ 2456
Description 给你一个n个数的数列,其中某个数出现了超过n div 2次即众数,请你找出那个数. Input 第1行一个正整数n.第2行n个正整数用空格隔开. Output 一行一个正整数表 ...
- MVC Action,Service中筛选int 和list<int>
action: public ActionResult DeleteByID(int id) { this.MessageService.DeleteMailTemplate(id); var fro ...
- Struts2基本包作用详解
asm-3.3.jar作用:操作java字节码的类库包路径及主要类:未提供 asm-commons-3.3.jar作用:提供了基于事件的表现形式包路径及主要类:未提供 asm-tree-3.3.jar ...