事件处理程序和事件处理程序之间有什么区别听众? [英] What's the difference between event handlers & listener?

查看:147
本文介绍了事件处理程序和事件处理程序之间有什么区别听众?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript中的事件处理程序和事件侦听器有什么区别?当事件出现时,它们都执行一个功能。
我真的不知道何时使用事件处理程序和何时使用事件侦听器。

What is the difference between event handlers and event listeners in JavaScript? They both execute a function when the event appears. I don't really get when to use event handlers and when to use event listeners.

推荐答案

没有什么区别;

为了事件处理的目的,将函数与DOM元素相关联的方式有很多种。当标准不断变化时(或者仅仅因为实现者讨厌或困难),差异就会重新出现,但最终机制本质上是相同的。

There are different ways of associating functions with DOM elements for the purpose of event handling, that's all. The differences emerged back when standards were in flux (or just because implementors were ornery or difficult) but ultimately the mechanisms are essentially the same.

如果您对哪种事件处理程序感到困惑要使用注册,您可以:

If you're confused about what sort of event handler registration to use, you can:


  • 阅读有关该主题的更多信息,并选择一种可能使用的方法(可能逐个浏览器);

  • 选择一种流行的JavaScript框架并使用其附加处理程序的机制

  • Read more about the topic and choose an approach to use, perhaps on a browser-by-browser basis;
  • Choose one of the popular JavaScript frameworks and use its mechanism for attaching handlers

这篇关于事件处理程序和事件处理程序之间有什么区别听众?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆