Js事件

笔记

event.currentTargetevent.target的区别

  • currentTarget事件处理的元素
  • target触发此事件的元素
function hide(e){ 
  e.currentTarget.style.visibility = "hidden";
   // When this function is used as an event handler: 
  this === e.currentTarget
}
var ps = document.getElementsByTagName('p');

for(var i = 0; i < ps.length; i++){ 
  //false -> 停止事件冒泡
  ps[i].addEventListener('click', hide, false);
}

你可能感兴趣的:(Js事件)