1.capture 捕获阶段 先父后子
let btn3=document.querySelector(".btn3");
let box1=document.querySelector(".box1");
btn3.addEventListener("click",function(){
console.log("子元素");
}, true);
box1.addEventListener("click",function(){
console.log(2);
},true);
capture 属性变为true
2.冒泡阶段 先子后父亲
<div οnclick="console.log(2);">
<button οnclick="console.log(1);">事件只能再冒泡阶段捕获</button>
</div>//1,2
3.使用js 进行 事件的绑定
let btn2=document.querySelector(".btn2");
btn2.οnclick=function(e){
alert("hello 杰宝!");
}
4.另外两种绑定事件的方法
<button οnclick="alert('hello');">使用HTML的on属性绑定点击事件</button><br>
<button οnclick="clickFun()">使用HTML的on属性绑定点击事件</button><br>
function clickFun(){
alert("I AM HAPPY TODAY");
}
直接声明 或者绑定函数