zoukankan      html  css  js  c++  java
  • JavaScript之事件绑定多个序列执行方法

    //一种事件绑定多个方法:以加载事件为例
    function addEventLoad(func,isLog) {
        var oldOnLoad = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        } else {
            window.onload = function() {
                oldOnLoad();
                func();
            }
        }
        if(isLog != undefined && isLog == true)
            console.info("[addEventLoad:SUCCESS]:" + func);
        return this;
    }
    
    //拓展:一个节点绑定多种事件
    function addEvent(element,eventType,handle,bol){
        if (typeof handle != 'function') {
            throw new Error("[addEvent] func must be a function."); 
        } else{
            if(element.nodeType){
                throw new Error("[addEvent]  arguments:'element' id not element node!");
            } else {
                if(element.addEventListener){           //如果支持addEventListener
                    element.addEventListener(eventType, handle, bol);
                }else if(element.attachEvent){          //如果支持attachEvent
                    element.attachEvent("on" + eventType, handle);//IE8 以下
                }else{                                  //否则使用兼容的onclick绑定
                    element["on" + eventType] = handle;
                }
            }
        }
    }
    
    //拓展 function bind(element,eventType,fn){ if(element.addEventListener){ element.addEventListener(eventType, fn, false); }else if(element.attachEvent){ element.attachEvent('on'+ eventType, fn); } console.log('[bind] bind success.'); }

      

  • 相关阅读:
    WPF资源字典使用
    忍住你的痛苦
    WPF附加属性
    一致性Hash算法详解
    登录注册
    REST
    资源访问
    参与Bean的生命周期
    sqlserver中查询横表变竖表的sql语句简析
    C#跨线程修改控件——从MSIL和汇编看Invoke, 多线程, 事件与事件委托
  • 原文地址:https://www.cnblogs.com/johnnyzen/p/7851353.html
Copyright © 2011-2022 走看看