冒泡与阻止冒泡

1
2
3
4
5
<div id="box">
<h1>标题标题标题标题标题标题标题标题</h1>
<img id="img_test" width="500px" height="300px" src="">
<p>这是段落这是段落这是段落这是段落这是段落这是段落这是段落这是段落这是段落</p>
</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
<script type="text/javascript">
(function(){
var __box = document.getElementById('box');
var __imgTest = document.getElementById('img_test');
__box.addEventListener('click',function(){
alert("点击box");
},false);
__imgTest.addEventListener('click',function(){
alert("点击选中图片");
window.event? window.event.cancelBubble = true : e.stopPropagation();
},false);
})();
</script>