(004)dom_dom2级事件处理程序

dom2级事件处理程序

dom2级定义了两个方法:addEventListener() removeEventListener()

接收三个参数:要处理的事件名,作为事件处理程序的函数,布尔值(true事件捕获,false事件冒泡)

 

<html>
    <head>
    </head>
    <body>
        <div id="box">
            <input type="button" value="button" id="btn" onclick="showMsg()">
            <input type="button" value="dom0 button" id="btn2">
            <input type="button" value="dom2 button" id="btn3">
        </div>
        <script type="text/javascript">
            function showMsg() {
                alert("hello");
            }

            function dom2Event() {
                alert("this is dom2 click event");
            }

            var btn2 = document.getElementById("btn2");
            btn2.onclick = function() {
                alert("this is dom0 click event");
            };
            //btn2.onclick = null;

            var btn3 = document.getElementById("btn3");
            btn3.addEventListener("click",dom2Event,false);
            //btn3.removeEventListener("click",dom2Event,false);

        </script>
    </body>
</html>

 

posted @ 2015-02-08 12:30  雪中飞雁  阅读(98)  评论(0)    收藏  举报