有没有办法在React中为输入发出KeyboardEvent?
我试过
this.input.dispatchEvent(new KeyboardEvent('keydown', {
key: 'Backspace',
bubbles: true,
cancelable: false
}));
this.input.dispatchEvent(new KeyboardEvent('keyup', {
key: 'Backspace',
bubbles: true,
cancelable: false
}));
this.input.dispatchEvent(new KeyboardEvent('keypress', {
key: 'Backspace',
bubbles: true,
cancelable: false
}));
但是没有一个触发任何处理程序(onKeyDown,onKeyPress,onKeyUp)
仅在手动按键时调用处理程序...