我有一个对象,我试图从传递给元素的 cssProperty 中删除该对象。我尝试了一些方法,但没有成功,我很茫然。
该对象看起来像
Object {background-color: "#91eae8"}
我尝试像这样删除它
delete this.cssProps.background-color;
delete this.cssProps[background-color];
delete this.cssProps['background-color'];
两者都不起作用并引发 viewModel 错误,因为它不知道我在做什么。我无法更改对象的引入方式以使其周围带有引号或类似内容。
最佳答案
在 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
关于javascript - 从对象中删除值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37217506/