Jquery操作下拉框(DropDownList)的取值赋值实现代码(王欢)

1. 获取选中项:

  1. 获取选中项的Value值:
  2. $('select#sel option:selected').val();
  3. 或者
  4. $('select#sel').find('option:selected').val();
  5. 获取选中项的Text值:
  6. $('select#seloption:selected').text();
  7. 或者
  8. $('select#sel').find('option:selected').text();

2. 获取当前选中项的索引值:

  1. $('select#sel').get(0).selectedIndex;

3. 获取当前option的最大索引值:

  1. $('select#sel option:last').attr("index")

4. 获取DropdownList的长度:

  1. $('select#sel')[0].options.length;
  2. 或者
  3. $('select#sel').get(0).options.length;

5. 设置第一个option为选中值:

  1. $('select#sel option:first').attr('selected','true')
  2. 或者
  3. $('select#sel')[0].selectedIndex = 0;

6. 设置最后一个option为选中值:

  1. $('select#sel option:last).attr('selected','true')

7. 根据索引值设置任意一个option为选中值:

  1. $('select#sel')[0].selectedIndex =索引值;索引值=0,1,2....

8. 设置Value=4 的option为选中值:

  1. $('select#sel').attr('value','4');
  2. 或者
  3. $("select#sel option[value='4']").attr('selected', 'true');

9. 删除Value=3的option:

  1. $("select#sel option[value='3']").remove();

10.删除第几个option:

  1. $(" select#sel option ").eq(索引值).remove();索引值=0,1,2....
  2. 如删除第3个Radio:
  3. $(" select#sel option ").eq(2).remove();

11.删除第一个option:

  1. $(" select#sel option ").eq(0).remove();
  2. 或者
  3. $("select#sel option:first").remove();

12. 删除最后一个option:

  1. $("select#sel option:last").remove();

13. 删除dropdownlist:

  1. $("select#sel").remove();

14.在select后面添加一个option:

  1. $("select#sel").append("f");

15. 在select前面添加一个option:

  1. $("select#sel").prepend("0");

16. 遍历option:

  1. $(' select#sel option ').each(function (index, domEle) {
  2. //写入代码
  3. });

Jquery操作下拉框(DropDownList)的取值赋值实现代码(王欢)的更多相关文章

  1. Jquery操作下拉框(DropDownList)实现取值赋值

    Jquery操作下拉框(DropDownList)想必大家都有所接触吧,下面与大家分享下对DropDownList进行取值赋值的实现代码 1. 获取选中项: 获取选中项的Value值: $('sele ...

  2. Jquery操作复选框(CheckBox)的取值赋值实现代码

    赋值 复选框 CheckBox 遍历 取值  1. 获取单个checkbox选中项(三种写法): $("input:checkbox:checked").val() 或者 $(&q ...

  3. jQuery操作下拉框的text值和val值

    jQuery操作下拉框的text值和val值 1,JS源码 <select name="select1" id="select1" style=" ...

  4. JQuery操作下拉框 select

    要实现这种效果: html代码 1<script src="js/jquery-1.7.2.min.js"></script> 2 <table> ...

  5. JQuery操作下拉框

    转载自下面的链接,很有用的. http://www.cnblogs.com/yrhua/archive/2012/11/04/2753571.html 要实现这种效果: HTML代码 <scri ...

  6. jquery获取下拉框中的循环值

    <select class="test" id="projectno" name="projectno"> <option ...

  7. Jquery中的CheckBox、RadioButton、DropDownList的取值赋值实现代码

    随着Jquery的作用越来越大,使用的朋友也越来越多.在Web中,由于CheckBox. Radiobutton . DropDownList等控件使用的频率比较高,就关系到这些控件在Jquery中的 ...

  8. jQuery对下拉框Select操作总结

    jQuery对下拉框Select操作总结 转自网络,留做备用 jQuery获取Select元素,并选择的Text和Value: 1. $("#select_id").change( ...

  9. jquery对下拉框的操作

     jQuery对下拉框的操作 /获取第一个option的值 $('#test option:first').val(); //最后一个option的值 $('#test option:last').v ...

随机推荐

  1. python selenium自动化(二)自动化注册流程

    需求:使用python selenium来自动测试一个网站注册的流程. 假设这个网站的注册流程分为三步,需要提供比较多的信息: 在这个流程里面,需要用户填入信息.在下拉菜单中选择.选择单选的radio ...

  2. java后端模拟表单提交

    代码可实现文本域及非文本域的处理 请求代码: /** * 上传 * * @param urlStr * @param textMap * @param fileMap * @return */ pub ...

  3. 比较escape、encodeURI、encodeURIComponent

    估计很多前端工程师并不清楚escape,encodeURI, encodeURIComponent的区别,也不知道什么时候该用哪个方法,以及这些方法为什么要被用到,下面我主要来阐述一下这三个方法的区别 ...

  4. 通过分析 JDK 源代码研究 TreeMap 红黑树算法实现--转

    TreeMap 和 TreeSet 是 Java Collection Framework 的两个重要成员,其中 TreeMap 是 Map 接口的常用实现类,而 TreeSet 是 Set 接口的常 ...

  5. Helpers\Document

    Helpers\Document The document class is a collection of useful methods for working with files. To get ...

  6. iCloud之旅

    1.创建BIDTinyPixDocument类 #import <UIKit/UIKit.h> //创建文档类 @interface TinyPixDocument : UIDocumen ...

  7. 结合源码看nginx-1.4.0之nginx事件驱动机制详解

    目录 0. 摘要 1. nginx事件模块组织结构 2. nginx事件模块数据结构及类图 3. nginx事件模块运行机制 4. 练习:一个简单的事件驱动模块 5. 小结 6. 参考源码

  8. LeetCode 345

    Reverse Vowels of a String Write a function that takes a string as input and reverse only the vowels ...

  9. poj 2195 二分图最优匹配 或 最小费用最大流

    就是最基本的二分图最优匹配,将每个人向每个房子建一条边,权值就是他们manhattan距离.然后对所有权值取反,求一次最大二分图最优匹配,在将结果取反就行了. #include<iostream ...

  10. U-boot新手入门

    U-boot新手入门 一.编译U-boot 二.U-boot命令详解 1.帮助命令 # help autoscr -run script from memory base -print or set ...