[英]React: How to catch `onInput` event with `InputEvent` arguments on `contentEditable` div?
我需要从InputEvent
中捕获historyUndo
和historyRedo
。 问题是,我的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.