常用代码段收集

事件代理

function _addEvent(obj, type, fn){
    return obj.addEventListener(type, fn, false)
}

function delegate(obj, className, type, fn){
    var dc =  ' ' + className + ''

    function cb(e){
        var target = e.target,
            c
        while(target !== obj){
            c = target.getAttribute('class') + ''
            if ( c.indexOf(className) !== -1){
                fn.call(target, e)
            }
            target = target.parentNode
        }
    }
    _addEvent(obj, type, cb)
}
© 404mzk all right reserved,powered by Gitbookhttp://blog.404mzk.com 该文件修订时间: 2018-08-14 23:03:24

results matching ""

    No results matching ""