The example in this article tells jquery how to get the color value of a CSS to return RGB. Share to everyone for your reference, specific as follows:
The CSS code is as follows:
A, a:link, a:visited {color: #4188FB;}
A:active, A:focus, a:hover {color: #FFCC00;}
The JS code is as follows:
var Link_col = $ ("A:link"). CSS ("color");
alert (Link_col); Returns RGB (65, 136, 251)
Jquey seems to set the color, using the RGB format.
Use the following function to convert RGB to the #xxxx (HEX) format.
var rgbstring = "RGB (0, 70, 255)"; Get this in whatever way.
var parts = Rgbstring.match (/^rgb\ (\d+), \s* (\d+), \s* (\d+) \) $/);
Parts now should is ["RGB (0, 255", "0", "", "255"]
Delete (parts[0));
for (var i = 1; I <= 3; ++i) {
Parts[i] = parseint (parts[i)). toString ();
if (parts[i].length = = 1) parts[i] = ' 0 ' + parts[i];
}
var hexstring = Parts.join ('); "0070FF"
or use this function.
function Rgb2hex (RGB) {
RGB = Rgb.match (/^rgb\ (\d+), \s* (\d+), \s* (\d+) \) $/);
function Hex (x) {return
("0" + parseint (x). toString). Slice ( -2);
}
Return "#" + Hex (rgb[1]) + hex (rgb[2]) + hex (rgb[3));
I hope this article will help you with the jquery program design.