1. 程式人生 > >獲取select被選中的option的值

獲取select被選中的option的值

選中項 nbsp 技術 技術分享 中項 cte ted com class

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