javascript16进制颜色转换为RGB

[javascript] function toRGB(hexColor) { return { r: parseInt(hexColor.slice(1, 3), 16), g: parseInt(hexColor.slice(3, 5), 16), b: parseInt(hexColor.slice(5, 7), 16) }; } function toRGB1(hexColor) { var matches = hexColor.match(/\w\w/g); return { r: parseInt(matches[0], 16), g: parseInt(matches[1], 16), b: parseInt(matches[2], 16) }; } function toRGB2(hexColor) { var hex = parseInt(hexColor.slice(1), 16); return { r: hex >> 16, g: hex >> 8 & 0xff, b: hex & 0xff }; } console.info(toRGB('#76400E')); console.info(toRGB1('#76400E')); console.info(toRGB2('#76400E')); [/javascript]
posted @ 2011-03-14 12:56  7hihi  阅读(155)  评论(0编辑  收藏  举报