//顏色16進位轉RGB方法 String.prototype.colorRgb = function(){ var sColor = this.toLowerCase(); //十六進位顏色值的正則表達式 var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/... ...
//顏色16進位轉RGB方法 String.prototype.colorRgb = function(){ var sColor = this.toLowerCase(); //十六進位顏色值的正則表達式 var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/; // 如果是16進位顏色 if (sColor && reg.test(sColor)) { if (sColor.length === 4) { var sColorNew = "#"; for (var i=1; i<4; i+=1) { sColorNew += sColor.slice(i, i+1).concat(sColor.slice(i, i+1)); } sColor = sColorNew; } //處理六位的顏色值 var sColorChange = []; for (var i=1; i<7; i+=2) { sColorChange.push(parseInt("0x"+sColor.slice(i, i+2))); } return "[" + sColorChange.join(",") + ",0.6]"; } return sColor; };