Created
April 22, 2015 00:53
-
-
Save RyoSugimoto/6ef7cc69506ef5d5f8cc to your computer and use it in GitHub Desktop.
イベントリスナを追加・削除する(旧IE対応)。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var addEvent, | |
removeEvent; | |
if (typeof window.addEventListener === 'function') { | |
addEvent = function (el, type, fn) { el.addEventListener(type, fn, false); }; | |
removeEvent = function (el, type, fn) { el.removeEventListener(type, fn, false); }; | |
} else if (typeof document.attachEvent === 'function') { | |
addEvent = function (el, type, fn) { el.attachEvent('on' + type, fn); }; | |
removeEvent = function (el, type, fn) { el.detachEvent('on' + type, fn); }; | |
} else { | |
addEvent = function (el, type, fn) { el['on' + type] = fn; }; | |
removeEvent = function (el, type, fn) { el['on' + type] = null; }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment