zoukankan      html  css  js  c++  java
  • jquery html select 清空保留第一项

    <select id="a">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <select>
    //...引入jquery.js
    方法1:
    <script>
    var b=$("#a option:first").text();
    $("#a").html('<option>'+b+'</option>');
    </script>
     
    方法2:$("#a option:not(:first)").remove();
     
     
    //参考
       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();
    
  • 相关阅读:
    图片完全填充CardView区域
    调用系统相机拍照并展示
    Android开发之加载GIF图片
    使用SatelliteMenu创建动画菜单
    swift中简单KVC和KVO的使用
    swift GCD的简单使用
    swift协议的使用方法和注意事项
    swift找window,导航栏的简单使用,Controller通过闭包传值简单示例
    swift中闭包的使用
    swift中UIButton的使用
  • 原文地址:https://www.cnblogs.com/guoyachao/p/9203953.html
Copyright © 2011-2022 走看看