1.addEventListener() :方法用于向指定元素添加事件句柄。// Internet Explorer 8 及更早IE版本不支持,Opera 7.0 及 Opera 更早版本也不支持。

语法:element.addEventListener(eventfunctionuseCapture);

解决方法:attachEvent() 方法来添加事件句柄

跨浏览器的解决方法:

var x = document.getElementById("myBtn");
if (x.addEventListener) {                    //所有主流浏览器,除了 IE 8 及更早 IE版本
    x.addEventListener("click", myFunction);
} else if (x.attachEvent) {                  // IE 8 及更早 IE 版本
    x.attachEvent("onclick", myFunction);
}
 

相关文章:

  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
  • 2022-01-14
猜你喜欢
  • 2022-02-01
  • 2022-01-18
  • 2021-08-16
相关资源
相似解决方案