美文网首页
事件委托

事件委托

作者: 郭海杰 | 来源:发表于2019-11-13 16:57 被阅读0次

    ```

    <script>

    window.onload = function () {

            var addEvent = (function (...args) {

                getEvent.call(this)

                if (window.addEventListener) {

                    return function (...args) {

                        ele.addEventListener(type, getEvent)

                    }

                } else if (window.attachEvent) {

                    return function (...args) {

                        ele.attachEvent("on" + type, getEvent)

                    }

                }

            })()

            var ele = document.getElementsByClassName('Oul')[0]

            var type = "click"

            addEvent(ele, type, getEvent)

            function getEvent(e) {

                if (e) {

                    console.log(e.target)

                }

            }

        }

    </script>

    ```

    相关文章

      网友评论

          本文标题:事件委托

          本文链接:https://www.haomeiwen.com/subject/zhvyvctx.html