首页 > 其他 > 详细

React

时间:2020-03-23 11:36:26      阅读:74      评论:0      收藏:0      [点我收藏+]

事件对象: 

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;//获取值
    let val = this.refs.username.value //根据ref获值
    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 ref="username" aid=‘1111‘ onClick={this.getMsg}>点击获值</button> <br /> <button onClick={this.setMsg}>改变值</button> </div> ) } } export default Index

  

React

原文:https://www.cnblogs.com/finnlee/p/12550884.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!