[HTML] 纯文本查看 复制代码 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#par{
width:400px;height:400px;background:white; border:1px solid red;
}
#son{width:200px;height:200px;background:rgb(200,0,0);}
</style>
</head>
<body>
<div id='par'>
<div id="son"></div>
</div>
</body>
<script>
var par = document.getElementById('par');
var son = document.getElementById('son');
son.onclick=function(e){
var e = e ||event;
alert('点击了par');
//阻止事件冒泡
// 标准浏览器有效 IE不行
//e.stopPropagation();
//没有兼容性问题阻止事件冒泡
e.cancelBubble = true;
}
par.onclick=function(){
alert('点击了son');
}
</script>
</html>
---------------------
|