获取select的 options 索引值
$('.selectList').change(function () {
var myselect = document.querySelector('.selectList');
var index = myselect.selectedIndex
console.log(index);
//一:JavaScript原生的方法
var myselect=document.getElementById(“test”);//1:拿到百度select对象:
var index=myselect.selectedIndex ; // selectedIndex代表的是你所选中项的index
var val= myselect.options[index].value;//3:拿到选中项options的value:
var text= myselect.options[index].text;//4:拿到选中项options的text:
//二:jQuery方法(前提是已道经加载了jquery库)回
1:var options=$(“#test option:selected”); //获取选中的项
2:alert(options.val()); //拿到选中项的值答
3:alert(options.text()); //拿到选中项的文本