Home  >  Article  >  Web Front-end  >  RGB转换实现代码,淘宝前端开发工程师笔试题_javascript技巧

RGB转换实现代码,淘宝前端开发工程师笔试题_javascript技巧

WBOY
WBOYOriginal
2016-05-16 18:16:221308browse

例如: #1234ff 输出 #1234ff
#123 输出 #123

#12345g 输出 #12345g

复制代码 代码如下:

function RGB(rgb)
{
reg=/^#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})$/;
if ( reg.test(rgb) )
rgb='rgb('+parseInt(RegExp.$1,16)+","+parseInt(RegExp.$2,16)+","+parseInt(RegExp.$3,16)+')';
return rgb;
}

演示代码:

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn