获取select被选中的option的值

Posted 此地

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取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);
    })

 弹窗结果

以上是关于获取select被选中的option的值的主要内容,如果未能解决你的问题,请参考以下文章