• jquery操作select(取值,设置选中)


    jquery操作select(增加,删除,清空)  

    $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发
     
    var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的
     
    var checkValue=$("#select_id").val(); //获取Select选择的Value
     
    var checkIndex=$("#select_id ").get(0).selectedIndex; //获取Select选择的索引值
     
    var maxIndex=$("#select_id option:last").attr("index"); //获取Select最大的索引值
     

    jQuery添加/删除Select的Option项:

    $("#select_id").append("<option value='Value'>Text</option>"); //为Select追加一个Option(下拉项)
    
    $("#select_id").prepend("<option value='0'>请选择</option>"); //为Select插入一个Option(第一个位置)
    
    $("#select_id option:last").remove(); //删除Select中索引值最大Option(最后一个)
    
    $("#select_id option[index='0']").remove(); //删除Select中索引值为0的Option(第一个)
    
    $("#select_id option[value='3']").remove(); //删除Select中Value='3'的Optiona
    
    $("#select_id option[text='4']").remove(); //删除Select中Text='4'的Optiona
    
    内容清空:$("#charCity").empty();

     jQuery获取Select选择的TextValue: 

    $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发
     
    var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的text
     
    var checkValue=$("#select_id").val(); //获取Select选择的Value
     
    var checkIndex=$("#select_id ").get(0).selectedIndex; //获取Select选择的索引值
     
    var maxIndex=$("#select_id option:last").attr("index"); //获取Select最大的索引值

    通过表单-和name 取值

    var frmCustomer = $("#frmCustomer");//表单
    $(frmCustomer).find("select[name='is_buy'] option:selected").val()

    转:https://www.cnblogs.com/hailexuexi/p/6708110.html

  • 相关阅读:
    Android Studio插件
    android漂亮的对话框项目sweet-alert-dialog
    Android中Context详解 ---- 你所不知道的Context
    Bundle对象的使用
    Android利用Http下载文件
    文件缓存(配合JSON数组)
    android studio sqlite操作代码片段
    Android中使用ListView实现分页刷新(线程休眠模拟)(滑动加载列表)
    Android Studio 配置使用百度api (附带简单样例)
    9套Android实战经典项目资料分享给大家
  • 原文地址:https://www.cnblogs.com/fps2tao/p/9435240.html
Copyright © 2020-2023  润新知