Today, when JQuery is used to obtain the value of background-color in the style, the obtained color value is displayed in different formats than Chrome and Firefox in IE. in IE, the color value is displayed in HEX format [# ffff00 ], chrome and Firefox display [rgb (255,255, 0)] in GRB format, and what I need is a hexadecimal color value, which is used for storage to the database, find the following code on the Internet to solve the problem:
Copy codeThe Code is as follows:
$. Fn. getHexBackgroundColor = function (){
Var rgb = background (this).css ('background-color ');
If (! $. Browser. msie ){
Rgb = rgb. match (/^ rgb \ (\ d +), \ s * (\ d +), \ s * (\ d +) \) $ /);
Function hex (x ){
Return ("0" + parseInt (x). toString (16). slice (-2 );
}
Rgb = "#" + hex (rgb [1]) + hex (rgb [2]) + hex (rgb [3]);
}
Return rgb;
}
In this way, all are displayed in HEX format and have been verified.