事件捕获和冒泡.html 973 Bytes
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>事件捕获和冒泡</title>
</head>
<body>
<div class="cl">
  <ul>
    <li><a href="#">点我</a></li>
  </ul>
</div>
<script>
function getTag(tagName){
  return document.getElementsByTagName(tagName)[0]
};

getTag('ul').addEventListener('click',function(event){
  console.log('ul')
});

getTag('li').addEventListener('click',function(event){
  console.log('li')
});

getTag('a').addEventListener('click',function(event){
  console.log('a')
});

getTag('div').addEventListener('click',function(event){
  console.log('div')
});
<!-- 捕获
getTag('ul').addEventListener('click',function(event){
  console.log('ul')
},true);

getTag('li').addEventListener('click',function(event){
  console.log('li')
},true);

getTag('a').addEventListener('click',function(event){
  console.log('a')
},true);

getTag('div').addEventListener('click',function(event){
  console.log('div')
},true); -->
</script>
</body>
</html>