jquery css color value returns RGB?

后端 未结 3 1763
旧巷少年郎
旧巷少年郎 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:37

    Here you go, this will allow you to use $(selector).getHexBackgroundColor() to return the hex value easily :

    $.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(16)).slice(-2);}
        return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
    }
    

提交回复
热议问题