例如: #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;
}
演示代码: