• jQuery 增加 删除 修改select option


     jQuery获取Select选择的Text和Value:

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

          2. var checkValue=jQuery("#select_id").val();   //获取Select选择的option Value

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

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

    jQuery添加/删除Select的Option项:

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

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

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

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

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

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

    内容清空:

          jQuery("#select_id").empty();

  • 相关阅读:
    这里下载QT速度飞快QT下载(多种下载通道+所有版本)
    一个查找窗口和子窗口的MFC类
    office 2007 安装和激活
    kafaka安装和使用及分析
    flume安装和使用
    Hbase的使用和分析
    Nginx源码安装
    hadoop集群下安装hive
    hadoop集群(完全分布式)下hbase的安装和配置
    linux下时区设置和时间同步
  • 原文地址:https://www.cnblogs.com/wangzhen/p/5773695.html
Copyright © 2020-2023  润新知