首页 > 技术文章 > this.refs['hh']获取dom对象,this.refs['hh'].value获取dom对象的值

yaomengli 2018-06-28 09:38 原文

<div id="app"></div>
<script type="text/babel">
var App=React.createClass({
handle:function(e){
e.preventDefault()
console.log(this.refs['hh'].value)
},
render:function(){
return(
<form action="" onSubmit={this.handle}>
<input type="text" defaultValue="hjkhk" ref="hh"/>
<button type="onSubmit">提交</button>
</form>
)
}
});
ReactDOM.render(
<App/>,
document.getElementById("app")
)

推荐阅读