这篇文章主要介绍了关于javascript获取内联样式与嵌入式样式的实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
通过style属性设置背景图案
change color
/*css*/
#change {
border: 1px solid black;
width: 200px;
height: 200px;
text-align: center;
line-height: 200px;
}//js change.style.backgroundColor="purple";

在侧边栏设置一个颜色选择器,将change的背景颜色设置为选择的颜色,此时颜色选择器的颜色是使用内联样式的方式添加的。

css
颜色选择器
change color
问题:
当颜色选择器的颜色是使用嵌入式或者外部引入的方式添加时,javascript的style属性无效,获取不到颜色值。
解决方法:
立即学习“Java免费学习笔记(深入)”;
javascript的style属性只能获取内联样式,对于外部引入样式和嵌入式样式需要用currentStyle属性。但是,currentStyle在Firefox和Chrome下不支持,需要使用如下兼容性代码:
HTMLElement.prototype.defineGetter("currentStyle", function () {
return this.ownerDocument.defaultView.getComputedStyle(this, null);
});Title
颜色的选择
change color












