1
<!DOCTYPE HTML>
<html>
<body>
<style type="text/css">
#a {background-color:blue;width:100px;height:200px;}
#b {background-color:red;margin-left:25px;width:50px;height:100px;}
</style>
<div id="a">a
<div id="b">b</div>
</div>
<script>
document.getElementById("a").onclick = function() {console.log("A is clicked");}
document.getElementById("b").onclick = function(event) {console.log("B is clicked");}
document.onclick = function() {console.log("Document is clicked");}
</script>
</body>
</html>
上面的代碼是事件冒泡的演示。如何將事件冒泡代碼更改爲在js中捕獲
問題:
1.I知道冒泡和捕獲是兩個相反的相位。我能理解這種方式嗎?事件的性質正在冒泡。
2.我沒有在網上看到太多的捕捉例子,所以如果我想改變上面的代碼捕捉事件,如何改變?
不支持IE –
可能的重複http://stackoverflow.com/questions/4616694/what-是事件冒泡和捕獲 – jeremy
其重複http://stackoverflow.com/questions/17339856/issue-with-event-bubbling-in-js – Hariharan