RGB color value to HTML 16 (HEX) Code JS function _javascript Skills

Source: Internet
Author: User

Copy Code code as follows:

Go to a fixed-length hexadecimal string, not enough to fill 0
function Zero_fill_hex (num, digits) {
var s = num.tostring (16);
while (S.length < digits)
s = "0" + s;
return s;
}

Damn it, how did you find out how to use JavaScript to figure out a background color, you have to parse
function Rgb2hex (RGB) {
Nnd, firefox/ie not the same, Fxck
if (Rgb.charat (0) = = ' # ')
return RGB;
var n = number (RGB);
var ds = Rgb.split (/\d+/);
var decimal = number (Ds[1]) * 65536 + number (ds[2)) * 256 + number (ds[3));
Return "#" + Zero_fill_hex (decimal, 6);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.