时间冒泡

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#box{
width: 100%;
height: 600px;
background: red;
overflow: hidden;
}
#box1{
width: 80%;
height: 400px;
margin: 100px auto;
background: blue;
overflow: hidden;
}
#box2{
width: 60%;
height: 200px;
margin: 100px auto;
background: yellow;
}
</style>
</head>
<body>
<div id="box">
<div id="box1">
<div id="box2">

</div>
</div>
</div>
<script type="text/javascript">
var box = document.getElementById("box")
var box1 = document.getElementById("box1")
var box2 = document.getElementById("box2")
document.onclick = fn;
box.onclick =fn;
box1.onclick =fn;
box2.onclick =fn;
function fn ( ev ){
ev = ev|| event;
//ev.cancelBubble = true;
alert(this.id)
}
</script>
</body>
</html>

posted @ 2017-03-10 10:17  张正-博客园  阅读(139)  评论(0编辑  收藏  举报