jquery #color到rgba?

dar*_*ryl 5 rgb jquery colors

是否可以将颜色转换#ff0000为rgb?

所以转换#ff0000rgb(255,0,0);

我很确定这是必须的,我只是不知道如何.任何见解都会很棒!

Pau*_*aul 8

你可以使用:

var s = "#ff0000";
var patt = /^#([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})$/;
var matches = patt.exec(s);
var rgb = "rgb("+parseInt(matches[1], 16)+","+parseInt(matches[2], 16)+","+parseInt(matches[3], 16)+");";
alert(rgb);
Run Code Online (Sandbox Code Playgroud)


Raf*_*fay 6

.css("background-color")将返回rgb http://api.jquery.com/css/

这里是小提琴http://jsfiddle.net/3nigma/msRqv/1/