//当一个元素同时处理多个函数,这里使用按钮

//addEventListener(string类型,处理函数,boolean);

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
<input type="button" id="btn"/>
//同一个按钮btn
document.getElementById("btn").addEventListener(
      //(事件因为是string类型,所有要用双引号括起来),匿名函数,(boolean值为true时,在捕获阶段触发事件,false时,在冒泡阶段触发事件)
"click",function(){
          console.log("函数1");
},false
)
//同一个按钮btn
document.getElementById("btn").addEventListener(
"click",function(){
          console.log("函数2");
},false
)
//同一个按钮btn
document.getElementById("btn").addEventListener(
"click",function(){
          console.log("函数3");
},false
)

//removeEventListener 解绑事件方法
//解绑事件必须使用命名函数
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄