console
let btnCon = document.querySelector('.btnCon');
let btn = document.querySelector('.btnCon div');
btnCon.addEventListener('click', c);
btn.addEventListener('click', c);
function c(event) {
event = event || wind
console.log(event );
console.log('事件的目标 =>', event.target);
console.log("绑定事件的元素 =>", event.currentTarget);
console.log(event.currentTarget === event.target);
console.log("被触发的事件类型 => ",event.type);
console.log('调用事件处理程序的阶段:0表示这个时间没有事件正在被处理,1表示捕获阶段,2表示“处于目标”,3表示冒泡阶段');
console.log(event.eventPhase);
event.stopPropagation();
event.stopImmediatePropagation();
event.preventDefault();
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
</style>
</head>
<body>
<div class="btnCon">
<button class="btn">
<div>
<span>按钮</span>
</div>
</button>
</div>
<script></script>
</body>
</html>
.btnCon {
width: 300px;
height: 300px;
border: 1px solid yellow;
}
.btn {
width: 200px;
height: 200px;
}
.btn div {
width: 100px;
height: 100px;
border: 1px solid red;
}
.btn div span {
background-color: #ccc;
}