2016-11-02 101 views
0

如何删除使用只有JavaScript的背景颜色和透明度属性(不jQuery的!)。的Javascript去除背景颜色和透明度

我尝试这样做:

document.getElementById('darkOverlay').style.removeProperty("background-color"); 
document.getElementById('darkOverlay').style.removeProperty("opacity"); 

,但没有奏效。我

回答

2

您只需通过属性设置为空字符串重置属性:

document.getElementById('darkOverlay').style.backgroundColor=""; 
document.getElementById('darkOverlay').style.opacity=""; 

或将它们设置为你喜欢的默认值:

document.getElementById('darkOverlay').style.backgroundColor="transparent"; 
document.getElementById('darkOverlay').style.opacity="1"; 
1
document.getElementById("darkOverlay").removeAttribute("style"); 

正常工作...... 作品只有当你把你的不透明度属性和背景风格

+0

不为我工作,两者在风格 – utdev

0

尝试

的document.getElementById( 'darkOverlay')。style.backgroundColor ='透明'; document.getElementById('darkOverlay')。style.opacity = 1;

0

试试这个:

var element = document.getElementById('darkOverlay'); 
element.style.background-color = null; 
element.style.opacity = null; 
+0

'element.style.background-color'不JAV一个可行的变量符号ascript。使用'element.style.backgroundColor'或'element.style ['background-color']''。 – connexo