<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#outer{
margin:20px auto;
padding:20px;
width:300px;
height:300px;
background:#008000;
}
#inner{
padding:20px;
width:200px;
height:200px;
background:blue;
}
#center{
padding:20px;
width:100px;
height:100px;
background:yellow;
}
</style>
</head>
<body>
<div id='outer'>
<div id='inner'>
<div id='center'></div>
</div>
</div>
<script>
var outer = document.getElementById('outer'),inner = document.getElementById('inner'),center = document.getElementById('center');
//使用DOM0级事件绑定给元素的某一个行为绑定的方法,都是在行为触发后的冒泡阶段把方法执行的
document.body.onclick = function(){
console.log('body')
}
outer.onclick = function(){
console.log('outer')
}
inner.onclick = function(){
console.log('inner')
}
center.onclick = function(){
console.log('center')
}
//addEventListener 第一个参数是行为的类型 第二个参数是给当前的行为定义的方法 第三个参数是控制在哪个阶段发生:true 在捕获阶段发生 false在冒泡阶段发生
document.body.addEventListener('click',function(){
console.log('body')
},false)
outer.addEventListener('click',function(){
console.log('outer')
},true)
inner.addEventListener('click',function(){
console.log('inner')
},false)
//输出 outer inner body
</script>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有