{"id":1509,"date":"2026-01-24T10:50:30","date_gmt":"2026-01-24T02:50:30","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=1509"},"modified":"2026-01-24T10:50:30","modified_gmt":"2026-01-24T02:50:30","slug":"%e9%a2%9c%e8%89%b2%e8%bd%ac%e6%8d%a2%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2026\/01\/24\/%e9%a2%9c%e8%89%b2%e8%bd%ac%e6%8d%a2%e5%99%a8\/","title":{"rendered":"\u989c\u8272\u8f6c\u6362\u5668"},"content":{"rendered":"\n<p>\u597d\uff0c\u8fd9\u4e2a\u6211\u76f4\u63a5\u7ed9\u4f60\u4e00\u4e2a<strong>\u4e13\u4e1a\u7ea7\u3001\u53ef\u5728\u7ebf\u4f7f\u7528\u7684\u300c\u989c\u8272\u8f6c\u6362\u5668\u300d\u5b8c\u6574\u5b9e\u73b0<\/strong> \ud83c\udfa8<br><strong>\u4e00\u4e2a HTML \u6587\u4ef6\u5373\u53ef\u8fd0\u884c<\/strong>\uff0c\u652f\u6301\u591a\u79cd\u989c\u8272\u683c\u5f0f\u4e92\u8f6c\uff0c\u4ee3\u7801\u6e05\u6670\u3001\u597d\u6269\u5c55\uff0c\u62ff\u53bb\u5c31\u80fd\u5f53\u5de5\u5177\u7ad9\u7528\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 \u652f\u6301\u7684\u989c\u8272\u683c\u5f0f<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>HEX \u21c4 RGB<\/li>\n\n\n\n<li>RGB \u21c4 HSL<\/li>\n\n\n\n<li>HEX \u21c4 HSL<\/li>\n\n\n\n<li>\u5b9e\u65f6\u989c\u8272\u9884\u89c8<\/li>\n\n\n\n<li>\u4e00\u952e\u8f6c\u6362<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udcc4 \u5b8c\u6574\u4ee3\u7801\uff08HTML + CSS + JavaScript\uff09<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6587\u4ef6\u540d\u793a\u4f8b\uff1a<code>color-converter.html<\/code><\/p>\n<\/blockquote>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;!DOCTYPE html&gt;\n&amp;lt;html lang=&quot;zh-CN&quot;&gt;\n&amp;lt;head&gt;\n&amp;lt;meta charset=&quot;UTF-8&quot;&gt;\n&amp;lt;title&gt;\u989c\u8272\u8f6c\u6362\u5668 | HEX \/ RGB \/ HSL&amp;lt;\/title&gt;\n&amp;lt;style&gt;\n    body {\n        font-family: Arial, Helvetica, sans-serif;\n        background: #f4f6f8;\n        padding: 40px;\n    }\n    .container {\n        max-width: 720px;\n        margin: auto;\n        background: #fff;\n        padding: 30px;\n        border-radius: 12px;\n        box-shadow: 0 6px 20px rgba(0,0,0,.1);\n    }\n    h1 {\n        text-align: center;\n    }\n    label {\n        display: block;\n        margin-top: 15px;\n        font-weight: bold;\n    }\n    input {\n        width: 100%;\n        padding: 10px;\n        margin-top: 6px;\n        font-size: 16px;\n    }\n    button {\n        margin-top: 20px;\n        padding: 12px;\n        width: 100%;\n        font-size: 16px;\n        background: #007bff;\n        color: white;\n        border: none;\n        border-radius: 8px;\n        cursor: pointer;\n    }\n    button:hover {\n        background: #0056b3;\n    }\n    .preview {\n        margin-top: 25px;\n        height: 80px;\n        border-radius: 8px;\n        border: 1px solid #ddd;\n    }\n    .note {\n        margin-top: 15px;\n        color: #666;\n        font-size: 14px;\n    }\n&amp;lt;\/style&gt;\n&amp;lt;\/head&gt;\n\n&amp;lt;body&gt;\n&amp;lt;div class=&quot;container&quot;&gt;\n    &amp;lt;h1&gt;\ud83c\udfa8 \u989c\u8272\u8f6c\u6362\u5668&amp;lt;\/h1&gt;\n\n    &amp;lt;label&gt;HEX\uff08\u5982 #ff6600\uff09&amp;lt;\/label&gt;\n    &amp;lt;input id=&quot;hex&quot; placeholder=&quot;#ff6600&quot;&gt;\n\n    &amp;lt;label&gt;RGB\uff08\u5982 255, 102, 0\uff09&amp;lt;\/label&gt;\n    &amp;lt;input id=&quot;rgb&quot; placeholder=&quot;255, 102, 0&quot;&gt;\n\n    &amp;lt;label&gt;HSL\uff08\u5982 24, 100%, 50%\uff09&amp;lt;\/label&gt;\n    &amp;lt;input id=&quot;hsl&quot; placeholder=&quot;24, 100%, 50%&quot;&gt;\n\n    &amp;lt;button onclick=&quot;convertColor()&quot;&gt;\u8f6c\u6362\u989c\u8272&amp;lt;\/button&gt;\n\n    &amp;lt;div class=&quot;preview&quot; id=&quot;preview&quot;&gt;&amp;lt;\/div&gt;\n\n    &amp;lt;div class=&quot;note&quot;&gt;\n        \u652f\u6301 HEX \u21c4 RGB \u21c4 HSL \u81ea\u52a8\u8bc6\u522b\u8f6c\u6362\n    &amp;lt;\/div&gt;\n&amp;lt;\/div&gt;\n\n&amp;lt;script&gt;\nfunction convertColor() {\n    const hexInput = document.getElementById(&quot;hex&quot;).value.trim();\n    const rgbInput = document.getElementById(&quot;rgb&quot;).value.trim();\n    const hslInput = document.getElementById(&quot;hsl&quot;).value.trim();\n\n    let rgb;\n\n    if (hexInput) {\n        rgb = hexToRgb(hexInput);\n    } else if (rgbInput) {\n        rgb = parseRgb(rgbInput);\n    } else if (hslInput) {\n        rgb = hslToRgb(parseHsl(hslInput));\n    } else {\n        alert(&quot;\u8bf7\u8f93\u5165\u4e00\u79cd\u989c\u8272\u683c\u5f0f&quot;);\n        return;\n    }\n\n    const hex = rgbToHex(rgb);\n    const hsl = rgbToHsl(rgb);\n\n    document.getElementById(&quot;hex&quot;).value = hex;\n    document.getElementById(&quot;rgb&quot;).value = `${rgb.r}, ${rgb.g}, ${rgb.b}`;\n    document.getElementById(&quot;hsl&quot;).value = `${hsl.h}, ${hsl.s}%, ${hsl.l}%`;\n\n    document.getElementById(&quot;preview&quot;).style.background = hex;\n}\n\n\/* HEX -&gt; RGB *\/\nfunction hexToRgb(hex) {\n    hex = hex.replace(&quot;#&quot;, &quot;&quot;);\n    if (hex.length === 3) {\n        hex = hex.split(&quot;&quot;).map(x =&gt; x + x).join(&quot;&quot;);\n    }\n    const bigint = parseInt(hex, 16);\n    return {\n        r: (bigint &gt;&gt; 16) &amp;amp; 255,\n        g: (bigint &gt;&gt; 8) &amp;amp; 255,\n        b: bigint &amp;amp; 255\n    };\n}\n\n\/* RGB \u5b57\u7b26\u4e32\u89e3\u6790 *\/\nfunction parseRgb(str) {\n    const &#x5B;r, g, b] = str.split(&quot;,&quot;).map(x =&gt; parseInt(x.trim()));\n    return { r, g, b };\n}\n\n\/* RGB -&gt; HEX *\/\nfunction rgbToHex({ r, g, b }) {\n    return &quot;#&quot; + &#x5B;r, g, b].map(x =&gt;\n        x.toString(16).padStart(2, &quot;0&quot;)\n    ).join(&quot;&quot;);\n}\n\n\/* RGB -&gt; HSL *\/\nfunction rgbToHsl({ r, g, b }) {\n    r \/= 255; g \/= 255; b \/= 255;\n    const max = Math.max(r, g, b);\n    const min = Math.min(r, g, b);\n    let h, s, l = (max + min) \/ 2;\n\n    if (max === min) {\n        h = s = 0;\n    } else {\n        const d = max - min;\n        s = l &gt; 0.5 ? d \/ (2 - max - min) : d \/ (max + min);\n        switch (max) {\n            case r: h = (g - b) \/ d + (g &amp;lt; b ? 6 : 0); break;\n            case g: h = (b - r) \/ d + 2; break;\n            case b: h = (r - g) \/ d + 4; break;\n        }\n        h *= 60;\n    }\n\n    return {\n        h: Math.round(h),\n        s: Math.round(s * 100),\n        l: Math.round(l * 100)\n    };\n}\n\n\/* HSL \u5b57\u7b26\u4e32\u89e3\u6790 *\/\nfunction parseHsl(str) {\n    let &#x5B;h, s, l] = str.replace(\/%\/g, &quot;&quot;).split(&quot;,&quot;).map(x =&gt; parseFloat(x));\n    return { h, s, l };\n}\n\n\/* HSL -&gt; RGB *\/\nfunction hslToRgb({ h, s, l }) {\n    s \/= 100;\n    l \/= 100;\n\n    const c = (1 - Math.abs(2 * l - 1)) * s;\n    const x = c * (1 - Math.abs((h \/ 60) % 2 - 1));\n    const m = l - c \/ 2;\n\n    let r = 0, g = 0, b = 0;\n\n    if (h &amp;lt; 60) &#x5B;r, g, b] = &#x5B;c, x, 0];\n    else if (h &amp;lt; 120) &#x5B;r, g, b] = &#x5B;x, c, 0];\n    else if (h &amp;lt; 180) &#x5B;r, g, b] = &#x5B;0, c, x];\n    else if (h &amp;lt; 240) &#x5B;r, g, b] = &#x5B;0, x, c];\n    else if (h &amp;lt; 300) &#x5B;r, g, b] = &#x5B;x, 0, c];\n    else &#x5B;r, g, b] = &#x5B;c, 0, x];\n\n    return {\n        r: Math.round((r + m) * 255),\n        g: Math.round((g + m) * 255),\n        b: Math.round((b + m) * 255)\n    };\n}\n&amp;lt;\/script&gt;\n&amp;lt;\/body&gt;\n&amp;lt;\/html&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\ude80 \u4f7f\u7528\u65b9\u6cd5<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u65b0\u5efa <code>color-converter.html<\/code><\/li>\n\n\n\n<li>\u7c98\u8d34\u4ee3\u7801<\/li>\n\n\n\n<li>\u6253\u5f00\u5373\u53ef\u4f7f\u7528\uff08\u672c\u5730 \/ \u670d\u52a1\u5668\u90fd\u884c\uff09<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u597d\uff0c\u8fd9\u4e2a\u6211\u76f4\u63a5\u7ed9\u4f60\u4e00\u4e2a\u4e13\u4e1a\u7ea7\u3001\u53ef\u5728\u7ebf\u4f7f\u7528\u7684\u300c\u989c\u8272\u8f6c\u6362\u5668\u300d\u5b8c\u6574\u5b9e\u73b0 \ud83c\udfa8\u4e00\u4e2a HTM&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2026\/01\/24\/%e9%a2%9c%e8%89%b2%e8%bd%ac%e6%8d%a2%e5%99%a8\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1509","post","type-post","status-publish","format-standard","hentry","category-1"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=1509"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1509\/revisions"}],"predecessor-version":[{"id":1510,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1509\/revisions\/1510"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=1509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=1509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=1509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}