获取某个dom元素上面都绑定了哪些事件 包括addEventLi

2020-04-21  本文已影响0人  cooqi

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
            EVENT_LIST = new Array();
                        _addEventListener = Element.prototype.addEventListener;
                        Element.prototype.addEventListener = function(event,fn) {
                        EVENT_LIST.push({"event": event, "element": this})
                        console.log(EVENT_LIST,fn)
                        _addEventListener.apply(this, arguments);
            };
        </script>
</head>
<body>
    <div onclick="a()" id="test">123</div>
    <script>
        document.getElementById("test").addEventListener("click", function(){
            a();
        });
        function a(){
            alert(1)
        }
    </script>
</body>
</html>



上一篇 下一篇

猜你喜欢

热点阅读