获取select被选中的option的值


<select id="select">
      <option>绥江</option>
      <option>西江</option>
      <option>北江</option>
      <option>贺江</option>
      <option>新兴江</option>
 </select>

 

$(function(){
        //jquery方法
        var options = $("#select option:selected");
        alert(options.val());
        alert(options.text());
        //js方法
        var selects = document.getElementById("select");
        var indexs = selects.selectedIndex;  //选中项的索引
        alert(selects.options[indexs].value);
        alert(selects.options[indexs].text);
    })

 弹窗结果


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM