2 回答

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個(gè)贊
function GetColoer16(obj){
var a = $(obj).css("color");
//判斷瀏覽器
有些是16的有些是rgb的
如果是rgb的你切割一下3個(gè)值
對(duì)每個(gè)值toString(16)然后拼接一下;
}

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超8個(gè)贊
function RGB2Hex(rgb){
var re = rgb.replace(/(?:\(|\)|rgb|RGB)*/g,"").split(",");//利用正則表達(dá)式去掉多余的部分
var hexColor = "#";
var hex = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
for (var i = 0; i < 3; i++) {
var r = null;
var c = re[i];
var hexAr = [];
while (c > 16) {
r = c % 16;
c = (c / 16) >> 0;
hexAr.push(hex[r]);
}
hexAr.push(hex[c]);
hexColor += hexAr.reverse().join('');
}
return hexColor;
}
添加回答
舉報(bào)