zoukankan      html  css  js  c++  java
  • AddEventListener 如何传递函数参数

    var EventUtil = new Object;
                    EventUtil.addEventHandler = function (oTarget, sEventType, fnHandler) {
                        if (oTarget.addEventListener) {
                            oTarget.addEventListener(sEventType, fnHandler, false);
                        } else if (oTarget.attachEvent) {
                            oTarget.attachEvent("on" + sEventType, fnHandler);
                        } else {
                            oTarget["on" + sEventType] = fnHandler;
                        }
                    };
                   
                            
                    function handleOnblur(div) {
                        
                        alert(div.id);
                    }               

          var o = function(){
                             var oDiv = document.getElementById("div1");
                            handleOnblur(oDiv);
                        }

                    window.onload = function() {
                        var oDiv = document.getElementById("div1");   

                        EventUtil.addEventHandler(oDiv, "blur", o);
                    }

    可以使用上面这种方式,也可以使用prototype 方式。

      function handleOnblur() {
                        alert(handleOnblur.prototype.addObject);
                    }           

    var oDiv = document.getElementById("div1");

    handleOnblur.prototype.addObject = oDiv;

  • 相关阅读:
    spring注解之@Lazy
    HttpClient之EntityUtils对象
    HTTP协议(Requset、Response)
    SpringBoot SpringSession redis SESSION
    Spring-session redis 子域名 session
    Spring Boot Servlet
    版本管理
    Spring AOP @Aspect
    Spring 事务配置的五种方式
    Spring <tx:annotation-driven>注解 JDK动态代理和CGLIB动态代理 区别。
  • 原文地址:https://www.cnblogs.com/wblade/p/1668926.html
Copyright © 2011-2022 走看看