The example in this article describes how jquery gets the color values in a style. Share to everyone for your reference. The specific analysis is as follows:
Today, using jquery to get the value of the Background-color in the style, we find that the color value in IE is not the same as that of Chrome and Firefox, ie displays "#ffff00" in the hex format, while Chrome, Firefox is in the GRB format to display "RGB (255,0,0)", because the need to store color values in the database, so you want to make the color value of the format unified (in fact, not uniform is also possible to save). Search for a bit, from a foreign website to get a section of code:
$.fn.gethexbackgroundcolor = function () {
var RGB = $ (this). CSS (' Background-color ');
RGB = Rgb.match (/^rgb\ (\d+), \s* (\d+), \s* (\d+) \) $/);
function Hex (x) {return ("0" + parseint (x). toString). Slice ( -2);}
return rgb= "#" + Hex (rgb[1]) + hex (rgb[2]) + hex (rgb[3));
The above definition is a jquery function that we can pass $ ("#bg"). Gethexbackgroundcolor (); Gets the RGB value of the Background-color of the label id= "BG".
Below do a little modification, is to add a judgment, if it is IE browser directly to get the value, if the non-IE browser will convert the value to RGB format:
$.fn.gethexbackgroundcolor = function () {
var RGB = $ (this). CSS (' Background-color ');
if (!$.browser.msie) {
RGB = Rgb.match (/^rgb\ (\d+), \s* (\d+), \s* (\d+) \) $/);
function Hex (x) {return ("0" + parseint (x). toString). Slice ( -2);}
rgb= "#" + Hex (rgb[1]) + hex (rgb[2]) + hex (rgb[3));
return RGB;
}
I hope this article will help you with your jquery programming.