" />

获取select被选中的option的值

来源:博客园 分类: 文章浏览史 发布时间:2020-05-29 15:43:44 最后更新:2020-05-29 浏览:1355
转载声明:
本文为摘录自“博客园”,版权归原作者所有。
温馨提示:
为了更好的体验,请点击原文链接进行浏览
摘录时间:
2020-05-29 15:43:44

<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);
    })

 弹窗结果

php技术微信