是否可以将 #ff0000
之类的颜色转换为 rgb?
因此将#ff0000
转换为rgb(255,0,0);
我很确定这一定是可能的,我只是不知道如何实现。任何见解都会很棒!
最佳答案
您可以使用:
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);
关于jquery # 颜色转rgba?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6805740/