1. 程式人生 > >js獲取select下拉框中的值

js獲取select下拉框中的值

現在有一id為userType的下拉框,怎麼獲取選中的值:

1  使用者型別:
2  <select name="type" id="userType">
3     <option value="0">請選擇</option>
4     <option value="1">普通型別</option>
5     <option value="2">VIP型別</option>
6</select>        

js操作:

1 var myType = document.getElementById("userType");//獲取select物件
2 var index = myType.selectedIndex; //獲取選項中的索引,selectIndex表示的是當前所選中的index
3 myType.options[index].value;//獲取選項中options的value值
4 myType.options[index].text;//獲取選項中options的value值