獲取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刪除。