2016-09-20 148 views
0

我试图在颜色值更改时更改div的背景。这里是我的功能,接收颜色值:我如何使用refs来改变ReactJS中的样式类?

ChangeColor(oColor) { 
    this.props.ChangeColor(oColor); 
    console.log("Refs: ", this.refs.colorPicker.className); 
    }, 

这里是css类

.colorPicker { 
    padding-right: 25px; 
    background: #000; 
    display: inline; 
    margin-right: 5px; 
    } 

,这里是我的div元素,其背景需要在运行时更新。

<div ref='colorPicker' className={this.GetClass("colorPicker")} /> 

我不确定关于refs synatx,所以请帮助解决这个问题。谢谢。

回答

-1

我找到了。这里回答:

ChangeColor(oColor) { 
    this.props.ChangeColor(oColor); 
    this.refs.colorPicker.style.background = oColor; //this is how background will be updated 

    },