2016-05-13 153 views
0

我有一个对象,我试图从传递给元素的cssProperty中移除。我已经尝试了几件事情,但没有运气,我很茫然。从对象中删除值

物体看起来像

Object {background-color: "#91eae8"} 

,我已经试过像

delete this.cssProps.background-color; 

delete this.cssProps[background-color]; 

delete this.cssProps['background-color']; 

既不删除它一直并抛出视图模型错误,因为它不知道我在做什么。我无法改变对象是如何引用它或类似的东西的。

+0

是一个,那只是我想什么都 – zazvorniki

+3

你不是说'删除this.cssProps [“背景色”];'? –

+2

有没有这样的运营商'删除'在js使用'删除' –

回答

2

在CSS中没有这样的东西作为一个未定义的属性。他们都有默认值。所以试图删除一个属性不起作用。相反,您可以将值更改为不同的值以获得您想要的行为。

我会尝试做这些

this.style.backgroundColor = "inherit";//background will be the same as it's parent 
this.style.backgroundColor = "transparent";//background will show what is behind it 
this.style.backgroundColor = "inital"; //sets it to the default value 
+0

对于'CSSStyleDeclaration'(我认为你在谈论的是)_empty_属性''“'',你可以通过调用'removeProperty'来使属性为空。空值和默认值之间的区别在于,空属性不会覆盖另一个匹配规则的属性。默认情况下,CSSStyleDeclaration的属性都是空的。 –