React从输入发出KeyboardEvent

时间:2016-08-17 12:43:10

标签: javascript reactjs javascript-events

有没有办法在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)

仅在手动按键时调用处理程序...

0 个答案:

没有答案