to call onChange event after pressing Enter key

前端 未结 7 482
悲&欢浪女
悲&欢浪女 2020-12-02 05:19

I am new to Bootstrap and stuck with this problem. I have an input field and as soon as I enter just one digit, the function from onChange is called, but I want

7条回答
  •  感动是毒
    2020-12-02 06:00

    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()
                    }
                  }}
    />
    

提交回复
热议问题