组件三大组件 refs
作者:互联网
1. 字符串的ref (废弃)
<script type="text/babel">
//创建组件
class Demo extends React.Component{
showData=()=>{
// 使用react就不要使用document了
const input = document.getElementById('input1');
//alert(input.value)
console.log(this.refs.input1.value); // 真正的节点信息,不是虚拟节点
}
// 展示右侧输入框的数据
showData2=()=>{
console.log(this.refs.input2.value);
}
render(){
return (
<div>
<input ref ='input1' id= 'input1' type = 'text' placeholder = '点击按钮提示数据' />
<button onClick = {this.showData}>点我提示左侧的数据</button>
<input ref='input2' onBlur = {this.showData2} type
标签:input1,log,refs,value,组件,input,三大 来源: https://blog.csdn.net/tzgdd8912442/article/details/113871678