import React from 'react'
export default class App extends React.Component {
myref=React.createRef()
render() {
return (
<div>
{/* 获取输入框的内容 写法一 */}
<input ref="mytext"></input>
<button onClick={
()=>{
console.log(this.refs.mytext.value)
}
}>add 匿名函数触发</button>
{/* 获取输入框的内容 写法二 */}
<input ref={this.myref}></input>
<button onClick={
()=>{
console.log(this.myref.current.value)
}
}>add 匿名函数触发</button>
</div>
)
}
}
标签:console,log,输入框,用法,React,获取,add,ref,节点 From: https://www.cnblogs.com/kaibindirver/p/17351055.html