JavaScript select选择值改变触发事件

<!doctype html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>select选择值改变触发事件</title>
</head>
<body>
    <select id="oad" onchange="displayData()">
        <option value="1">功率</option>
        <option value="0">电流</option>
    </select>
    <script>
        function displayData() {
            var select = document.getElementById('oad');
            var oadTitle = select.options[select.selectedIndex].innerText;
            alert(oadTitle);
        }
    </script>
</body>
</html>

评论