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>
时间: 2024-10-08 13:46:04