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值


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM