如何在ReactJS onKeyPress事件中检测'Shift + Enter'?
这可能吗?
https://jsfiddle.net/jacobgoh101/cyLqfcts/3/
class App extends React.Component {
constructor(props) {
super(props);
this.handleKeyPress = this.handleKeyPress.bind(this);
}
handleKeyPress(e) {
console.log(e.key);
$('#app').append("<br/>" + e.key);
}
render() {
return ( < textarea defaultValue = {
""
}
onKeyPress = {
this.handleKeyPress
}
/>
);
}
}
ReactDOM.render(<App/>, document.getElementById('app'));
e.shiftKey
和e.nativeEvent.shiftKey
是同一件事。无论如何,感谢您的帮助。我会将您的答案标记为正确的。 - Jacob Goh