标签:console str highlight component export extends div class xtend
事件对象:
import React,{Component} from ‘react‘ class Index extends Component{ constructor(props){ super(props) this.state = { msg:‘张学友‘ } } getMsg=(event)=>{ alert(this.state.msg);
event.target.value;//获取值
console.log(event.target); //获取当前Dom节点 event.target.style.background = ‘red‘ ; //改变当前Dom的背景色
console.log(event.target.getAttribute(‘aid‘)); //获取当前Dom属性 } setMsg=()=>{ this.setState({ msg:‘刘德华‘ }) } render(){ return( <div> {this.state.msg} <button aid=‘1111‘ onClick={this.getMsg}>点击获值</button> <br /> <button onClick={this.setMsg}>改变值</button> </div> ) } } export default Index
标签:console str highlight component export extends div class xtend
原文地址:https://www.cnblogs.com/finnlee/p/12550884.html