event.js 691 Bytes
/**
 * 事件处理工具库
 */

//添加事件监听
exports.addEventHandler = function(target, type, func) {
    if (!target) {
        return;
    }
    if (target.addEventListener)
        target.addEventListener(type, func, false);
    else if (target.attachEvent)
        target.attachEvent("on" + type, func);
    else target["on" + type] = func;
};

//移除事件监听
exports.removeEventHandler = function(target, type, func) {
    if (!target) {
        return;
    }
    if (target.removeEventListener)
        target.removeEventListener(type, func, false);
    else if (target.detachEvent)
        target.detachEvent("on" + type, func);
    else delete target["on" + type];
};