流
window.onload = function(){
window.addEventListener("click", function(){
alert("Window (capture)");
}, true);
window.addEventListener("click", function(e){
alert("Window (bubble)");
}, false);
document.addEventListener("click", function(){
alert("Document (capture)");
}, true);
document.addEventListener("click", function(){
alert("Document (bubble)");
}, false);
document.getElementsByTagName("html")[0].addEventListener("click", function(){
alert("Html (capture)");
}, true);
document.getElementsByTagName("html")[0].addEventListener("click", function(){
alert("Html (bubble)");
}, false);
document.body.addEventListener("click", function(){
alert("Body (capture)");
}, true);
document.body.addEventListener("click", function(){
alert("Body (bubble)");
}, false);
document.getElementById("myDiv").addEventListener("click", function(){
alert("Div (capture)");
}, true);
document.getElementById("myDiv").addEventListener("click", function(e){
alert("Div (bubble)");
}, false);
}
冒泡
window.onload = function(){
window.onclick = function(){
alert("Window");
};
document.onclick = function(){
alert("Document");
};
document.documentElement.onclick = function(){
alert("Html");
};
document.body.onclick = function(){
alert("Body");
};
document.getElementById("myDiv").onclick = function(){
alert("Div");
};
}
捕获
window.onload = function(){
window.addEventListener("click", function(){
alert("Window");
}, true);
document.addEventListener("click", function(){
alert("Document");
}, true);
document.documentElement.addEventListener("click", function(){
alert("Html");
}, true);
document.body.addEventListener("click", function(){
alert("Body");
}, true);
document.getElementById("myDiv").addEventListener("click", function(){
alert("Div");
}, true);
}