function getSelectval(id){ var selId = document.getElementById(id); //獲取select的id var seleIndex =selId.selectedIndex; //獲取被選項的引索值 alert(selId.options[seleIndex].value); //獲取被選項的value
alert(selId.options[seleIndex].text); //獲取被選項的文本 }
<select id="sel" onchange="getSelectval('sel')"> <option selected value="1">val1</option> <option value="2">val2</option> <option value="3">val3</option> </select>
