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

window.onload 添加多个函数绑定

发布于 2018-04-08 阅读 530 次 Javascript
  1. window.onload = function(){alert(2)}
  2. function addEvent (fun) {
  3. var old = window.onload;
  4. if(typeof old != "function"){
  5. window.onload = fun;
  6. }else{
  7. window.onload = function(){
  8. old();
  9. fun();
  10. }
  11. }
  12. }
  13. function delegationforli(){
  14. var oul = document.getElementsByTagName('ul')[0];
  15. console.log(oul)
  16. oul.addEventListener('click',function(e){
  17. console.log(e.target);
  18. if(e.target && e.target.nodeName.toLowerCase() == 'li'){
  19. alert(e.target.innerHTML);
  20. }
  21. })
  22. }
  23. addEvent(delegationforli);