繁体   English   中英

React:如何在 `contentEditable` div 上使用 `InputEvent` 参数捕获 `onInput` 事件?

[英]React: How to catch `onInput` event with `InputEvent` arguments on `contentEditable` div?

我需要从InputEvent中捕获historyUndohistoryRedo 问题是,我的contentEditable div 给了我FormEvent而不是InputEvent

const inputChanged = (e: InputEvent) => {
  //Error here because e is FormEvent type not InputEvent
  if(e.inputType === 'historyUndo' || e.inputType === 'historyRedo')
  {
    ....
  }
}

return <div contentEditable={true} onInput={(e) => inputChanged(e)}>
  ....
</div>

如何在 div contentEditable 上捕获InputEvent

您要做的是访问事件的nativeEvent属性。 类似的东西。

const inputChanged = (e) => {
  if(e.nativeEvent.inputType === 'historyUndo' || e.nativeEvent.inputType === 'historyRedo')
  {
    ....
  }
}

return <div contentEditable={true} onInput={(e) => inputChanged(e)}>
  ....
</div>

暂无
暂无

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

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