当前位置:首页 > window.onload 添加多个函数绑定

window.onload 添加多个函数绑定

发布于 2018-04-08 阅读 449 次 Javascript
window.onload = function(){alert(2)}
function addEvent (fun) {
    var old = window.onload;
    if(typeof old != "function"){
        window.onload = fun;
    }else{
        window.onload = function(){
            old();
            fun();
        }
    }
}
function delegationforli(){
    var oul = document.getElementsByTagName('ul')[0];
    console.log(oul)
    oul.addEventListener('click',function(e){
        console.log(e.target);
        if(e.target && e.target.nodeName.toLowerCase() == 'li'){
            alert(e.target.innerHTML);
        }
    })
}
addEvent(delegationforli);