jquery css color value returns RGB?

后端 未结 3 1766
旧巷少年郎
旧巷少年郎 2020-12-06 00:58

In my CSS file:

a, a:link, a:visited { color:#4188FB; }
a:active, a:focus, a:hover { color:#FFCC00; }

I tried with:

var lin         


        
3条回答
  •  不思量自难忘°
    2020-12-06 01:29

    Some adjustes to function

    $.fn.getHexBackgroundColor = function() {
        var rgb = $(this).css('background-color');
        if (!rgb) {
            return '#FFFFFF'; //default color
        }
        var hex_rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); 
        function hex(x) {return ("0" + parseInt(x).toString(16)).slice(-2);}
        if (hex_rgb) {
            return "#" + hex(hex_rgb[1]) + hex(hex_rgb[2]) + hex(hex_rgb[3]);
        } else {
            return rgb; //ie8 returns background-color in hex format then it will make                 compatible, you can improve it checking if format is in hexadecimal
        }
    }
    

提交回复
热议问题