How to get input text value on click in ReactJS

后端 未结 2 1718
梦谈多话
梦谈多话 2021-01-30 12:55

I am learning ReactJS and I want to understand how to get the input text values in ReactJS using simple onclick event. I have followed there tutorial and although i am able to g

2条回答
  •  无人及你
    2021-01-30 13:38

    There are two ways to go about doing this.

    1. Create a state in the constructor that contains the text input. Attach an onChange event to the input box that updates state each time. Then onClick you could just alert the state object.

    2. handleClick: function() { alert(this.refs.myInput.value); },

提交回复
热议问题