javascript - React onFocus 和 onFocusCapture 的区别

标签 javascript reactjs dom-events

我想知道 react 事件之间有什么区别:onFocusonFocusCapture .我在 react 的文档页面上找不到合适的答案。

<OutlinedInput
    label="price from"
    onFocus={handlePriceFocus}
/>
<OutlinedInput
    label="price to"
    onFocusCapture={handlePriceFocus}
/>
就我而言,它似乎是 onFocusonFocusCapture执行相同的功能,因为我在使用这两个事件时没有注意到任何区别。

最佳答案

这就是 React 在他们的文档中所说的:

"The event handlers below are triggered by an event in the bubbling phase. To register an event handler for the capture phase, append Capture to the event name; for example, instead of using onClick, you would use onClickCapture to handle the click event in the capture phase." reactjs.org/docs/events


所以,我觉得这点没什么好说的了。我的理解就像没有“捕获”代码在事件之后执行,而“捕获”代码在事件之前执行。

关于javascript - React onFocus 和 onFocusCapture 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66798706/

相关文章:

javascript - 如何使用 JavaScript\JQuery 检查一个日期是否早于另一个日期?

javascript - 使用常用方法将“替换为”在 JavaScript Azure Function 中不起作用

javascript - Jquery 到 React js

javascript - 在 React 中正确渲染 HTML 标签

reactjs - 从 React (TypeScript) 导入事件类型

Javascript 触发函数两次,4 个函数中的 1 个不起作用

javascript - 拖动 .drag 时以绿色 .drop div 闪烁

javascript - React,调用无状态函数来组织代码,但是这个怎么绑定(bind)呢?

reactjs - 将命名和未命名参数传递给无状态组件

javascript - 在 JavaScript DOM 中,是否可以将整个按钮功能克隆到另一个?