JavaScript错误 – 无效的属性值

使用IE 6/7/8,我收到一个
JavaScript错误代码.

代码行是:

document.getElementById('all').style.backgroundColor = color;

IE 6/7/8是:

Invalid property value

提前致谢!

最佳答案 在DOM完全加载后你是在运行这段代码吗?也许没有“小组讨人喜欢的全部”呢?如果您使用的是Prototype,可以尝试:

document.observe("dom:loaded", function() { // Wait until everything is loaded.
   document.getElementById('panel-hlisting-all').style.background = color;
 });

只是一个想法 – 我无法在IE上测试它(谢天谢地/不幸的是),但如果你尝试了怎么办:

document.getElementById('panel-hlisting-all').style.backgroundColor = color;

添加:

另请注意,颜色必须是包含有效CSS颜色的字符串(#FFFFFF,rgb(255,255,255),rgba(255,255,255,1)).

点赞