码迷,mamicode.com
首页 > 其他好文 > 详细

获取select被选中的option的值

时间:2018-01-19 21:30:01      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:图片   fun   nbsp   弹窗   text   bsp   sel   png   document   

<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的值

标签:图片   fun   nbsp   弹窗   text   bsp   sel   png   document   

原文地址:https://www.cnblogs.com/suni/p/8318729.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!