八、React refs获取元素内容
在input和textarea标签上使用ref属性
<input type="text" placeholder="姓名" ref="author"/>
<textarea placeholder="评论" ref="text"></textarea>
在onSubmit={this.handleSubmit}的this.handleSubmit后面添加.bind(this)
在handleSubmit方法内获取input 和 textarea的输入值 并打印到控制台
let author = this.refs.author.value, text = this.refs.text.value; console.log(author + " " + text);
控制台效果