//html select

var x = $("#selectSort").val();  //获取选中的value值

获取select选中的索引:
 $("#selectSort").get(0).selectedindex;

($("#selectSort").find("option:selected").text();  //获取显示的文本值 即用户看到的值

$("#selectSort").html(""); //添加前先清空option

$("#selectSort").append('<option value="90">' + jsonsort[i].description + '</option>');

//dropdownlist

    LWSR.BLL.S_EmpBLL bll = new BLL.S_EmpBLL();
            DataTable sellnameDt = bll.GetModel("1,6");
            dropsellname.DataSource = sellnameDt;
            dropsellname.DataValueField = sellnameDt.Columns[0].ColumnName;  ////显示的value
            dropsellname.DataTextField = sellnameDt.Columns[1].ColumnName; //显示的文本 用户看见的值
            dropsellname.DataBind();
            dropsellname.Items.Insert(0, new ListItem("请选择"));  //顶端插入一个选项

1. JQuery为select控件增加/移除事件:

1.1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发

1.2. $("#select_id").unbind("change"); //为Select移除选择改变事件

2. 获取选中项的相关属性:

2.1. var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的Text

2.2. var checkValue=$("#select_id").val(); //获取Select选择的Value

2.3. var checkIndex=$("#select_id ").get(0).selectedIndex; //获取Select选择的索引值

3. JQuery获取select控件中特定的节点:

3.1. var maxIndex=$("#select_id option:first").attr("index"); //获取Select最小的索引值

3.2. var maxIndex=$("#select_id option:last").attr("index"); //获取Select最大的索引值

4. JQuery设置Select控件选中的项:

4.1. $("#select_id ").get(0).selectedIndex=1; //设置Select索引值为1的项选中

4.2. $("#select_id ").val(4); // 设置Select的Value值为4的项选中

4.3. $("#select_id option[text='jQuery']").attr("selected", true); //设置Select的Text值为jQuery的项选中  这个有jquery版本问题 jquery 1.4.2 可以, jquery-1.7.2.js不行!!自己可以试试

或者 $("select option:contains('Jquery')").attr('selected', true);

5. JQuery添加/删除Select的Option项:

5.1. $("#select_id").append("<option value='Value'>Text</option>"); //为Select追加一个Option(下拉项)

5.2. $("#select_id").prepend("<option value='0'>请选择</option>"); //为Select插入一个Option(第一个位置)

5.3. $("#select_id option:last").remove(); //删除Select中索引值最大Option(最后一个)

5.4. $("#select_id option[index='0']").remove(); //删除Select中索引值为0的Option(第一个)

5.5. $("#select_id option[value='3']").remove(); //删除Select中Value='3'的Option

5.5. $("#select_id option[text='4']").remove(); //删除Select中Text='4'的Option

html select 和dropdownlist小结收集的更多相关文章

  1. jQuery select操作控制方法小结

    需要注意的是,这里的代码好多是针对jquery 1.32以前的版本(以后的版本已经不支持@),所以替换为空测试下即可. jQuery获取Select选择的Text和Value: 语法解释: 1. $( ...

  2. KendoUI系列:DropDownList

    1.基本使用 1>.创建Input <input id="dropDownList" /> <link href="@Url.Content(&q ...

  3. [转]Dropdownlist doesn't postback after Page_ClientValidate()

    本文转自:http://stackoverflow.com/questions/2083929/dropdownlist-doesnt-postback-after-page-clientvalida ...

  4. [MVC4-基礎] 連動DropDownList - 使用jQuery、JSON

    剛開始學MVC4,以下是一些基礎的學習筆記! 先展示一下結果: 1.選擇申請部門 2.選好後申請部門鎖住防止USER修改並載入該部門所擁有的設備類型 一.資料庫 dept mf_fx 二.View ( ...

  5. ASP.NET MVC中DropDownList的使用

    Asp.net MVC中的DropDownLists貌似会让一开始从Asp.net Forms转过来的程序员造成不少迷惑.这篇文章讲述了为了使用DropDownLists,你需要在Asp.Net MV ...

  6. kendo-ui的MVVM模式

    摘要: MVVM(Model View ViewModel)是一种帮助开发者将数据从模型分离的设计模式.MVVM的ViewModel负责将数据对象从模型中分离出来,通过这种方式数据就很容易控制数据如何 ...

  7. ASP.Net MVC开发基础学习笔记:二、HtmlHelper与扩展方法

    一.一个功能强大的页面开发辅助类—HtmlHelper初步了解 1.1 有失必有得 在ASP.Net MVC中微软并没有提供类似服务器端控件那种开发方式,毕竟微软的MVC就是传统的请求处理响应的回归. ...

  8. 在.net中读写config文件的各种方法

    阅读目录 开始 config文件 - 自定义配置节点 config文件 - Property config文件 - Element config文件 - CDATA config文件 - Collec ...

  9. 【转】Hive的insert操作

    insert 语法格式为: 1. 基本的插入语法: insert overwrite table tablename [partition(partcol1=val1,partclo2=val2)] ...

随机推荐

  1. 移动端rem自适应布局(切图)

    本篇适用于初次使用rem为单位切图而无从下手的童鞋.核心是根据屏幕动态改变根元素字体大小,以达到适配各种屏幕.这只是一个拿来就用的教程.很多东西没有详细说明.不过对于快速做手机端切图很有帮助. 模板: ...

  2. Learning Git by Animations

    https://hujiaweibujidao.github.io/blog/2016/05/20/learning-git-by-animations/ http://learngitbranchi ...

  3. POJ 1117 Pairs of Integers

    Pairs of Integers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4133 Accepted: 1062 Des ...

  4. ELK系列七:Elasticsearch的集群配置和监控以及在部署ELK中踩的坑

    1.基本下载安装 #按照ELK系列一博客安装启动即可,没有大坑,注意一下权限即可 chmod -R 777 ./elasticsearch #此外没有java的,注意安装下JDK,我这次部署的环境是C ...

  5. vscode的vetur插件提示 [vue-language-server] Elements in iteration expect to have 'v-bind:key' directives错误的解决办法

    1.使用VS Code 出现如下问题,如图 Vue 2.2.0+的版本里,当在组件中使用v-for时,key是必须的. 2.更改vetur配置 vscode->文件->首选项->用户 ...

  6. Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGBitmapinfo' (aka) 'enum CGBitmapInfo')

    The constants for specifying the alpha channel information are declared with the CGImageAlphaInfo ty ...

  7. 【CF802C】Heidi and Library (hard) 费用流

    [CF802C]Heidi and Library (hard) 题意:有n个人依次来借书,第i人来的时候要求书店里必须有种类为ai的书,种类为i的书要花费ci块钱购入.而书店的容量只有k,多余的书只 ...

  8. 【BZOJ1004】[HNOI2008]Cards Burnside引理

    [BZOJ1004][HNOI2008]Cards 题意:把$n$张牌染成$a,b,c$,3种颜色.其中颜色为$a,b,c$的牌的数量分别为$sa,sb,sc$.并且给出$m$个置换,保证这$m$个置 ...

  9. iOS - Block的循环引用内存泄漏问题探索

    循环引用的原因 众所周知,ARC下用block会产生循环引用的问题,造成泄露的原因是啥呢? 最简单的例子,如下面代码: [self.teacher requestData:^(NSData *data ...

  10. 在 CSS 中,width 和 height 指的是内容区域的宽度和高度

    增加内边距.边框和外边距不会影响内容区域的尺寸,但是会增加元素框的总尺寸. 改变宽度就可以,去掉