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

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

<input type="button" />
//同一个按钮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 解绑事件方法
//解绑事件必须使用命名函数

相关文章:

  • 2022-12-23
  • 2021-06-15
  • 2021-11-03
  • 2021-07-28
  • 2021-04-17
  • 2022-02-09
  • 2021-04-14
猜你喜欢
  • 2021-11-07
  • 2021-03-30
  • 2022-12-23
  • 2021-04-19
  • 2021-12-20
  • 2022-12-23
  • 2022-02-07
相关资源
相似解决方案