Home > Web Front-end > JS Tutorial > body text

RGB conversion implementation code, Taobao front-end development engineer written test questions_javascript skills

WBOY
Release: 2016-05-16 18:16:22
Original
1381 people have browsed it

例如: #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需刷新才能执行]
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template