UNPKG

rabbit-simple-ui

Version:

A simple UI component library based on JavaScript

33 lines (31 loc) 1.04 kB
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /** * 解决事件监听兼容性问题 * @param {Object} obj对象 * @param {String} type事件类型,不带'on'前缀 * @param {Function} callback事件处理程序 */ export function bind(obj: Element | HTMLElement | Window | any, type: string, callback: any): void { if (obj.addEventListener) { // W3C内核 obj.addEventListener(type, callback); } else { // IE内核 obj.attachEvent(`on${type}`, callback); } } /** * 解决移除事件监听兼容性问题 * @param {Object} obj对象 * @param {String} type事件类型,不带'on'前缀 * @param {Function} callback事件处理程序 */ export function unbind(obj: Element | HTMLElement | Window | any, type: string, callback: any) { if (obj.removeEventListener) { // W3C内核 obj.removeEventListener(type, callback); } else { // IE内核 obj.detachEvent(`on${type}`, callback); } }