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");//禁用下拉框
本人一般用得比較多的就是第一種和最后一種。