JavaScript的event对象

JavaScript的event对象中

event.target指代的是:触发事件的元素

event.currentTarget指代的是:事件绑定的元素

复制代码
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
        <div id="test">
            <span>aaa</span>
            <span>bbb</span>
            <span>ccc</span>
        </div>
        <script>
            document.getElementById('test').addEventListener('click', function(ev){
                var ev = ev || window.event;
                console.log(ev.target);
                console.log(ev.currentTarget);
            }, false);
        </script>
    </body>
</html>

posted on 2015-12-16 22:35  蜀北乔少恭  阅读(261)  评论(0编辑  收藏  举报

导航