关于select 下拉框取值

1.获取选中的下拉框的索引:
var index = document.getElementById("ID").selectedIndex;//得到选中项的索引
var department =document.getElementById("ID").options[index].text.trim();//得到选中项的text值
var department1 =document.getElementById("ID").options[index].value.trim();//得到选中项的Value值
2.获取相应的option的索引:
var maxIndex = $(“#select_id :last”).get(0).index; //获取select最大索引值

var checkIndex = $(“#select_id”).get(0).selectedIndex;//获取Select选中项的索引值

var checkIndexs = $(‘option:selected’, ‘#select_id’).index(); //获取选中的select的索引

var checkIndexa =('#select_id option').index(('#select_id option').index((‘#select_id option:selected’)); //获取选中的select的索引

var checkIndex = $(‘#select_id’).prop(‘selectedIndex’); //获取选中的select的索引
3.判断是否被选中:
alert($(“#select_id”).find(“option[value=’Value值’]”).is(“:selected”)); //选中为true 没选中为false

alert(document.getElementById(“select_id”).options[1].selected); //判断选中为true 没选中为false
4.获取相应option的值:
var checkValue = $(‘#select_id option:first’).val();//获取第一个option的值

var checkValue =$(“#select_id option:last”).val();//最后一个option的值

var checkValue = $(‘#select_id option:eq(1)’).val();//获取第二个option的值 
5.禁用下拉框:
$("#ID").attr("disabled","disabled");//禁用下拉框

 本人一般用得比较多的就是第一种和最后一种。

转载于:https://www.cnblogs.com/A-R-E-S/p/10482020.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值