var select = document.getElementById('mySelect');
// 1. 獲取選中項的索引
var index = select.selectedIndex;
// 2. 獲取選中項的文本(用戶可見文字)
var text = select.options[index].text;
// 3. 獲取選中項的值(value 屬性)
var value = select.options[index].value; // 或 select.value
// 4. 獲取選中項的 DOM 元素
var option = select.options[index]; // 或 select.selectedOptions[0] (現代瀏覽器)
完整示例
<select id="fruit">
<option value="1">蘋果</option>
<option value="2" selected>香蕉</option>
<option value="3">橙子</option>
</select>
<button onclick="getSelected()">獲取選中項</button>
<script>
function getSelected() {
var sel = document.getElementById('fruit');
var idx = sel.selectedIndex;
var txt = sel.options[idx].text;
var val = sel.options[idx].value;
alert('文本:' + txt + ',值:' + val); // 文本:香蕉,值:2
}
</script>
jQuery 寫法(更簡潔)
// 文本
var text = $('#fruit option:selected').text(); // 或 $('#fruit').find('option:selected').text()
// 值
var value = $('#fruit').val(); // 直接獲取 select 的 value
// 綁定 change 事件即時獲取
$('#fruit').on('change', function() {
console.log('文本:', $(this).find('option:selected').text());
console.log('值:', this.value);
});