• 关于事件绑定的函数封装


    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>添加事件函数封装</title>
    <style>
    div{
      height: 100px;
       100px;
      background: red;
    }
    </style>
    </head>
    <body>
    <div id="div"></div>
    <script>
    function addListener(target,type,handler) {
      if(target.addEventListener) {
        target.addEventListener(type,handler,false)
      }else if(target.attachEvent) {
        target.attachEvent("on" + type,handler)
      }else{
        target["on" + type] = handler
      }
    }
    var oDiv = document.getElementById("div");
    function changeStyle() {
      this.style.backgroundColor = 'blue';
    }
    addListener(oDiv,'click',changeStyle)
    </script>
    </body>
    </html>

    关于事件绑定的函数封装有很多,只是做一个小的汇总!

  • 相关阅读:
    day 66
    day 66 作业
    day 65 作业
    day 55 Ajax
    day 56 forms组件
    day 59
    day 58 cookie与session 中间件
    day 54
    day 53
    day 52
  • 原文地址:https://www.cnblogs.com/shenwh/p/9030203.html
Copyright © 2020-2023  润新知