- render(){
- return(
- <div ref="inp" onClick={this.handleClick.bind(this)} >test</div>
- )
- }
则获取这个div内部的文本信息则为:
- handleClick(){
- let val = this.refs.inp.innerText;
- console.log(val);
- }
2 获取输入input框中的文本信息:
- class Test extends Component{
- constructor(props){
- super(props);
- this.state = {
- inp: ''
- }
- }
-
- handleChange(e){
- let val = e.target.value;
- this.setState({
- inp: val
- },function(){
- console.log(this.state.inp);
- })
- }
-
- render(){
- return(
- <input value={this.state.inp} onChange={this.handleChange.bind(this)}/>
- )
- }
- }