Dan*_* W. 4 javascript css firefox
在此示例中, Chrome将背景设置为红色,firefox和IE则不设置.
试:
document.getElementById("firefoxDiv").style['backgroundColor'] = "Red";
Run Code Online (Sandbox Code Playgroud)
和
document.getElementById("firefoxDiv").style['background-color'] = "Red";
Run Code Online (Sandbox Code Playgroud)
我宁愿能够使用外部CSS中使用的相同语法
background-color与内联使用javascript.style.backgroundColor =
谢谢你的帮助!
注意: 请不要 jQuery.
使用.style.setProperty(propertyName, value [, priority])而不是expando属性.
例:
document.getElementById("firefoxDiv").style.setProperty('background-color', 'red');
Run Code Online (Sandbox Code Playgroud)