var btn = document.getElementById("btn"); document.body.addEventListener("click", function() { console.log(event.eventPhase); //1 console.log(event.currentTarget); //HTMLBodyElement }, true); btn.addEventListener("click", function() { console.log(event.eventPhase); //2 console.log(event.currentTarget); //HTMLInputElement }); document.body.addEventListener("click", function() { console.log(event.eventPhase); //3 console.log(event.currentTarget); //HTMLBodyElement });
流程大概是:
document.body 捕获阶段 --> btn 目标对象阶段 --> document.body 冒泡阶段