【js与jquery】如何获取选择的下拉菜单的值

来源:互联网 发布:熟悉使用办公软件 编辑:程序博客网 时间:2024/05/17 01:38
[html] view plaincopy
  1. <select   name="test" id="type">    
  2.   <option   value="0">请选择</option>    
  3.   <option   value="1">第一</option>    
  4.   <option   value="2">第二</option>    
  5.   <option   value="3">第三</option>    
  6.   <option   value="4">第四</option>    
  7.   </select>   

若要获取显示值第一 第二 第三之类的

var selectIndex = document.getElementById("type").selectedIndex;//获得是第几个被选中了var selectText = document.getElementById("type").options[selectIndex].text //获得被选中的项目的文本
alert(selectText);//得到显示的值
jquery实现以上效果:
var selectText=$("#type").val();


原创粉丝点击