首页javascriptselectJavascript Form - 如何获取选择选项文本

Javascript Form - 如何获取选择选项文本

我们想知道如何获取选择选项文本。

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
function fun(e) {
    document.getElementById('caption').innerHTML = e.options[e.selectedIndex].text
}

</script>
</head>
<body>
  <select onchange=fun(this)>
    <option id="apple">Apple</option>
    <option id="orange">Orange</option>
    <option id="pineapple">Pineapple</option>
    <option id="banana">Banana</option>
  </select>
  <p id="caption"></p>
</body>
</html>