我有一个代码,应该添加和删除样式.
(function (){
var elem = document.querySelector('div');
elem.style.backgroundColor = 'green';
elem.style.outline = 'solid red 5px';
elem.style.removeProperty('outline');
elem.style.removeProperty('backgroundColor');
})();
Run Code Online (Sandbox Code Playgroud)
我无法删除backgroundColor.我该如何解决?
这是我的jsFiddle示例http://jsfiddle.net/gjm550sL
将您的字符串更改'backgroundColor'为'background-color'...
elem.style.removeProperty('background-color');
Run Code Online (Sandbox Code Playgroud)
或者,您可以将其设置为background-color默认值transparent...
elem.style.backgroundColor = 'transparent';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
62 次 |
| 最近记录: |