📜  在 javascript 中捕获输入 - 无论代码示例

📅  最后修改于: 2022-03-11 14:58:23.609000             🧑  作者: Mango

代码示例1
//You can use onKeyPress directly on input field. onChange function changes 
//state value on every input field change and after Enter
//is pressed it will call a function search().

 {this.setState({query: event.target.value})}}
    onKeyPress={event => {
                if (event.key === 'Enter') {
                  this.search()
                }
              }}
/>