使用JavaScript将CSS系统颜色转换为十六进制?

3

1
好问题,但可能是从颜色名称获取颜色代码的重复。 - naveen
1个回答

1

看起来getComputedStyle函数运行正常。

Firebug输出(在http://artific.com/library/css-2-system-colors.html上运行):

var t = document.getElementsByClassName("window")[0]; window.getComputedStyle(t).backgroundColor;
"rgb(255, 255, 255)"

>>> var t = document.getElementsByClassName("menu")[0]; window.getComputedStyle(t).backgroundColor;
"rgb(240, 240, 240)"

>>> var t = document.getElementsByClassName("info")[0]; window.getComputedStyle(t).backgroundColor;
"rgb(225, 225, 225)"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接