The Code is as follows:
Copy codeThe Code is as follows:
Var br = {};
Br. eventRouter = {};
Br. eventRouter. addListen = function (el, eventType, func ){
If (! El. eventObjs ){
El. eventObjs = {};
}
If (! El. eventObjs [eventType]) {
El. eventObjs [eventType] = [];
Br. eventRouter. bindListen (el, eventType );
}
El. eventObjs [eventType]. push (func );
};
Br. eventRouter. removeListen = function (el, eventType, func ){
If (el. eventObjs & el. eventObjs [eventType]) {
For (var I = 0, len = el. eventObjs [eventType]. length; I <len; I ++ ){
Var item = el. eventObjs [eventType] [I];
If (func = item ){
El. eventObjs [eventType]. splice (I, 1 );
Return true;
}
}
}
Return false;
};
Br. eventRouter. bindListen = function (el, eventType ){
If (el. eventObjs & el. eventObjs [eventType]) {
El [eventType] = function (e ){
For (var I = 0, len = el. eventObjs [eventType]. length; I <len; I ++ ){
Var f = el. eventObjs [eventType] [I];
F. call (el, e );
}
};
}
};
The code is relatively simple and not explained too much. I also hope that you will be interested in providing bugs.