How to handle the `onKeyPress` event in ReactJS?
问题 How can I make the onKeyPress event work in ReactJS? It should alert when enter (keyCode=13) is pressed. var Test = React.createClass({ add: function(event){ if(event.keyCode == 13){ alert('Adding....'); } }, render: function(){ return( <div> <input type="text" id="one" onKeyPress={this.add} /> </div> ); } }); React.render(<Test />, document.body); 回答1: I am working with React 0.14.7, use onKeyPress and event.key works well. handleKeyPress = (event) => { if(event.key === 'Enter'){ console.log