react.js gives the identifier ref and gets the content

一个新手
Release: 2017-10-06 10:39:58
Original
1955 people have browsed it


import React,{Component} from 'react'import ReactDOM from 'react-dom'class App extends Component{ //给一个初始化状态 constructor(){ super(); this.state={ result:0 } } handChange=()=>{ //获取input a的类容,这个a就是我们给的标识ref="a" let a=this.refs.a.value||0; let b=this.refs.b.value||0; //改变状态,更新视图 this.setState({result:parseFloat(a)+parseFloat(b)}) } render(){ return ( 

+

{this.state.result}

) } } ReactDOM.render(,document.querySelector("#root"))
Copy after login

The above is the detailed content of react.js gives the identifier ref and gets the content. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!