zoukankan      html  css  js  c++  java
  • 原生js 通用事件绑定

     1 /*原文地址:http://ejohn.org/blog/flexible-javascript-events/*/
        http://blog.csdn.net/qi1271199790/article/details/53458043
    2 /** 3 * [addEvent &&removeEvent description] 4 * @param {[obj]} obj [绑定事件的对象] 5 * @param {str} type [绑定的事件的名称] 6 * @param {Function} fn [事件触发的回调函数] 7 */ 8 var txt=document.getElementById('txt'); 9 function addEvent(obj,type,fn){ 10 if(obj.attachEvent){ 11 obj['e'+type+fn] = fn; 12 obj[type+fn] = function(){ 13 obj['e'+type+fn](window.event); 14 }; 15 obj.attachEvent('on'+type,obj[type+fn]); 16 }else{ 17 obj.addEventListener(type,fn,false); 18 } 19 } 20 function removeEvent(obj,type,fn){ 21 if(obj.detachEvent()){ 22 obj.detachEvent('on'+type,obj[type+fn]); 23 obj[type+fn] = null; 24 }else{ 25 obj.removeEventListener(type,fn,false); 26 } 27 }
  • 相关阅读:
    Flutter 导航栏上添加搜索按钮
    tabController保活
    nav 选项卡
    flutter 毛玻璃
    [题解]CodeForces878 D
    [题解]CodeForces878C Tournament
    [题解]NOIP2012
    bzoj1070题解
    bzoj1061题解
    bzoj1059题解
  • 原文地址:https://www.cnblogs.com/lcddjm/p/5761371.html
Copyright © 2011-2022 走看看