猿问

js使用addEventListener调用onchange没有反应

<!DOCTYPE html>

<html>

    <head>

        <meta charset="UTF-8">

        <title></title>

    </head>

    <body>

        <select id="select-some" onchange="alert(this.value)"> 

            <option>sdfsd</option>

            <option>ssdfsdfd</option>

            <option>sdsdfsdfsfdsd</option>

        </select>

        <script>

            var selectSome = document.getElementById("select-some");

            selectSome.addEventListener("onchange", function () {

                alert(this.value);

            }, false);

        </script>

    </body>

</html>

为什么下面的js脚本没反应,而<select id="select-some" onchange="alert(this.value)">可以正常执行。

忽然笑
浏览 2800回答 1
1回答

呼如林

&nbsp; &nbsp; &nbsp; &nbsp; selectSome.addEventListener("change", function () {//onchange改为change&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(this.value);&nbsp; &nbsp; &nbsp; &nbsp; }, false);
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答