js 部分很简单,就是显示事件流的执行顺序。
window.onload = function(){
var outA = document.getElementById("outA");
var outB = document.getElementById("outB");
var outC = document.getElementById("outC");
outA.addEventListener('click',function(){alert("bubble1");},false);
outB.addEventListener('click',function(){alert("bubble2");},false);
outB.addEventListener('click',function(){alert("capture2");},true);
outC.addEventListener('click',function(){alert("target");},true);
outA.addEventListener('click',function(){alert("capture1");},true);
};
css用来渲染这三个 div
div#outA{
width:400px; height:400px; background:#CDC9C9;position:relative;
}
div#outB{
height:200; background:#0000ff;top:100px;position:relative;
}
div#outC{
height:100px; background:#FFB90F;top:50px;position:relative;
}
结构更简单,三个div
<div id="outA">
<div id="outB">
<div id="outC">
</div>
</div>
</div>
当点击divB的时候,我的理解应该输出是
capture1--capture2--bubble2--bubble1
为何实际结果是
capture1--bubble2--capture2--bubble1?
墨色风雨
德玛西亚99
相关分类