首页 > Web开发 > 详细

js 事件

时间:2017-09-05 18:36:32      阅读:203      评论:0      收藏:0      [点我收藏+]

1. 事件冒泡 :  

// 分别在 >= ie 9 和 < ie9 下测试

‘use strict‘;
var arr = [document, window, document.documentElement, document.body, document.querySelector(‘.container‘)];
while (arr.length){
  var e = arr.pop(arr);
  !function(e){
    if (e.addEventListener){
      e.addEventListener(‘click‘, function (event) {console.log(e.constructor.name);});
    }else{
      e.attachEvent(‘onclick‘, function (event) {console.log(e.constructor.name);});
    }
  }(e)
}

 

1. ie9 支持 elementTarget.addeventListener ,ie 9 以下不支持。

2. 默认都是事件冒泡的方式

js 事件

原文:http://www.cnblogs.com/Tachi/p/7479874.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!