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;

  • 相关阅读:
    LeetCode#160-Intersection of Two Linked Lists-相交链表
    LeetCode#2-Add Two Numbers-两数相加
    LeetCode#141-Linked List Cycle-环形链表
    LeetCode#66-Plus One-加一
    LeetCode#35-Search Insert Position-搜索插入位置
    LeetCode#203-Remove Linked List Elements-移除链表元素
    基姆拉尔森公式
    [leetcode] 树(Ⅲ)
    常用算法合集(一)
    离散数学 II(最全面的知识点汇总)
  • 原文地址:https://www.cnblogs.com/wblade/p/1668926.html
Copyright © 2011-2022 走看看