jquery#color to rgba? [英] jquery # colour to rgba?
本文介绍了jquery#color to rgba?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将#ff0000
转换为rgb?
Is it possible to convert a colour as such #ff0000
to rgb?
$ c>#ff0000 至 rgb(255,0,0);
So convert #ff0000
to rgb(255,0,0);
我很确定这必须是可能的,我只是不知道如何。
I'm pretty sure this has got to be possible, I just don't know how. Any insight would be great!
推荐答案
您可以使用:
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#color to rgba?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文