如何刪除使用只有JavaScript的背景顏色和透明度屬性(不jQuery的!)。的Javascript去除背景顏色和透明度
我嘗試這樣做:
document.getElementById('darkOverlay').style.removeProperty("background-color");
document.getElementById('darkOverlay').style.removeProperty("opacity");
,但沒有奏效。我
如何刪除使用只有JavaScript的背景顏色和透明度屬性(不jQuery的!)。的Javascript去除背景顏色和透明度
我嘗試這樣做:
document.getElementById('darkOverlay').style.removeProperty("background-color");
document.getElementById('darkOverlay').style.removeProperty("opacity");
,但沒有奏效。我
您只需通過屬性設置爲空字符串重置屬性:
document.getElementById('darkOverlay').style.backgroundColor="";
document.getElementById('darkOverlay').style.opacity="";
或將它們設置爲你喜歡的默認值:
document.getElementById('darkOverlay').style.backgroundColor="transparent";
document.getElementById('darkOverlay').style.opacity="1";
document.getElementById("darkOverlay").removeAttribute("style");
正常工作...... 作品只有當你把你的不透明度屬性和背景風格
嘗試
的document.getElementById( 'darkOverlay')。style.backgroundColor ='透明'; document.getElementById('darkOverlay')。style.opacity = 1;
試試這個:
var element = document.getElementById('darkOverlay');
element.style.background-color = null;
element.style.opacity = null;
'element.style.background-color'不JAV一個可行的變量符號ascript。使用'element.style.backgroundColor'或'element.style ['background-color']''。 – connexo
不爲我工作,兩者在風格 – utdev