为元素添加on方法

5年以前  |  阅读数:815 次  |  编程语言:JavaScript 
Element.prototype.on = Element.prototype.addEventListener;

NodeList.prototype.on = function (event, fn) {、
    []['forEach'].call(this, function (el) {
        el.on(event, fn);
    });
    return this;
};

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8