zoukankan      html  css  js  c++  java
  • Jquery操作下拉框(DropDownList)的取值赋值实现代码(王欢)

    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. });
  • 相关阅读:
    最短路之浇水
    agc031_d A Sequence of Permutations
    loj 3236 [POI2019 R1] Układ scalony
    CodeForces 1237H Balanced Reversals
    CodeForces 1320F Blocks and Sensors
    CodeForces 1340D Nastya and Time Machine
    agc037_f Counting of Subarrays
    nikkei2019_2_qual_e Non-triangular Triplets
    CodeForces 603E Pastoral Oddities
    Vue router / ElementUI,Ant Design Vue 重复点击导航路由报错解决方法
  • 原文地址:https://www.cnblogs.com/huanhuan1989/p/3238559.html
Copyright © 2011-2022 走看看