1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| String.prototype.toRGB = function(){ var _color = this, _rgb = []; if(_color.search(/^#[a-fA-F0-9]{3}$|^#[a-fA-F0-9]{6}$/) === 0){ if(this.length === 4){ _color = this.replace(/[a-fA-F0-9]/g, function(color){ return color + color; }) }
_color.replace(/[a-fA-F0-9]{2}/g, function(color){ _rgb.push(parseInt(color, 16)); }); return "rgb("+ _rgb.toString() + ")"; } console.error("类型错误"); return null; }
|