ReactJS - Is there a way to trigger a method by pressing the 'Enter' key inside <input/>?

前端 未结 4 719
长情又很酷
长情又很酷 2020-12-31 07:46

Using only onChange and value and while focused inside a , preferably without jQuery, is there a way to trigger a method by pressing

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 08:35

    You can add a onKeyPress to your input and make it equal the function you want to execute . You would just need to make sure the key pressed was the enter key using the event that is passed to the function as an argument

    Unfortunately can't just use the onchange method alone to get this result

提交回复
热议问题