聘我网

新概念招聘3.0

jQuery的事件处理机制实现

vote up0vote downstar

The DOM standard that eventually developed thus speciied that both strategies should be used; irst the event is captured from general to speciic, and then the event bubbles back up to the top of the DOM tree. Event handlers can be registered for either part of the process.

jQuery always registers event handlers for the bubbling phase of the model.

jQuery是如何实现在bubbling phase还是在capturing phase进行事件处理的呢?

 

1 个答复

vote up0vote downcheck

addEventListener():

var myDiv = document.getElementById('myDiv'); 
myDiv.addEventListener('click', OnMyDivClicked, false); // false = bubbling phase, true = capture phase 

function OnMyDivClicked(event) 
{ 
  switch(event.eventPhase) 
  { 
    case Event.CAPTURING_PHASE: 
      alert('capturing phase'); 
      break; 

    case Event.AT_TARGET: 
      alert('at target'); 
      break; 

    case Event.BUBBLING_PHASE: 
      alert('bubbling phase'); 
      break; 
  } 
} 
链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.