首页javascriptselectJavascript Form - 如何请使用DOM在下拉菜单中指向所选项目

Javascript Form - 如何请使用DOM在下拉菜单中指向所选项目

我们想知道如何请使用DOM在下拉菜单中指向所选项目。

<!DOCTYPE html>
<html>
<body>
  <select id="My_Select_Menu">
    <option value="Blue" selected="selected">blue</option>
  </select>
    <script type='text/javascript'>
    
        var sel = document.getElementById("My_Select_Menu");
        if (sel.options[sel.selectedIndex].value == "Blue") {
            console.log("hahaha");
        }
    
    </script>
</body>
</html>