八、React refs获取元素内容

inputtextarea标签上使用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);

控制台效果

 

posted @ 2018-01-23 13:24  journeyIT  阅读(31)  评论(0编辑  收藏  举报