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

前端 未结 4 713
长情又很酷
长情又很酷 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:42

    You just simply fire a function like this,

     {
        var key = event.keyCode || event.which;
        if (key === 13) {
            // perform your Logic on "enter" button 
            console.log("Enter Button has been clicked")
        }
    }}
    />;
    

提交回复
热议问题