简体   繁体   English

Javascript 事件和 React 事件之间有什么区别吗?

[英]Is there is any difference between Javascript events and React Events?

In javascript, we use onclick event and in React we use the onClick event.在 JavaScript 中,我们使用 onclick 事件,而在 React 中,我们使用 onClick 事件。 My question is event provides my React is the same as a javascript event or React handle event differently.我的问题是事件提供我的 React 与 javascript 事件相同或 React 处理事件不同。

React uses a synthetic event system, which is a cross-browser wrapper around the browser's native event. React 使用合成事件系统,它是围绕浏览器原生事件的跨浏览器包装器。 In most cases, a developer may not notice the differences, but they do exist:在大多数情况下,开发人员可能不会注意到这些差异,但它们确实存在:

  1. React synthetic events work identically across browsers. React 合成事件在浏览器中的工作方式相同。
  2. React event handlers cannot return false to prevent the default behavior. React 事件处理程序不能返回 false 以防止默认行为。
  3. React synthetic events always bubble.反应合成事件总是冒泡。
  4. Before React 17, React synthetic events cannot be used in an asynchronous way unless e.persist() is called.在 React 17 之前,除非调用 e.persist(),否则不能以异步方式使用 React 合成事件。
  5. React's synthetic event system for videos works the same way as HTML/JavaScript Events. React 的视频合成事件系统的工作方式与 HTML/JavaScript 事件相同。

onclick and onClick events are the same. onclickonClick事件是相同的。

The only difference is the capital of the "C".唯一的区别是大写的“C”。

Warning警告

onclick event is deprecated in javascript. javascript 中不推荐使用onclick事件。 Now, we use addEventListener and then onclick event inside.现在,我们在里面使用addEventListeneronclick事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM