本文介绍一个基于JavaScript的十六进制RGB色码转换工具。该工具通过HTML表单界面,实现十六进制颜色代码(如#RRGGBB)与RGB数值之间的相互转换。用户输入颜色值后,点击“转换”按钮即可实时获取对应格式的颜色代码,适用于前端开发中的颜色处理需求。
十六进制RGB色码转换工具实现
<html> <head> <title>十六进制RGB色码转换器 风越ASP代码生成器</title> </head> <!--第一步:先将下列代码复制到<head></head>之间:--> <style><!-- .slider_bar { background : menu; font-size : 0; z-index : 0; top : auto; left : 0; width : 9; height : 20; border : thin outset; position : absolute; cursor : NW-resize; } .slider { top : auto; left : 0; position : absolute; background: White; font-size : 10; height : 20; z-index : 0; width : 265; border : thin inset; text-align : center; } .small_box { top : auto; left : 270; position : absolute; font-size : 0; height : 20; z-index : 0; width : 20; border : thin inset; text-align : center; } .large_box { font-size : 0; height : 40; z-index : 0; width : 40; border : thin inset; text-align : center; } .button { background : Menu; top : auto; left : auto; position : absolute; font-size : 12; height : 20; z-index : 0; width : 120; border : thin outset; text-align : center; cursor : NW-resize; } .preset { top : auto; left : 270; position : absolute; font-size : 0; height : 15; z-index : 0; width : 15; border : thin inset; text-align : center; } .slider_box{ top: auto; left : auto; position : absolute; } --></style><style bogus="1"> .slider_bar { background : menu; font-size : 0; z-index : 0; top : auto; left : 0; width : 9; height : 20; border : thin outset; position : absolute; cursor : NW-resize; } .slider { top : auto; left : 0; position : absolute; background: White; font-size : 10; height : 20; z-index : 0; width : 265; border : thin inset; text-align : center; } .small_box { top : auto; left : 270; position : absolute; font-size : 0; height : 20; z-index : 0; width : 20; border : thin inset; text-align : center; } .large_box { font-size : 0; height : 40; z-index : 0; width : 40; border : thin inset; text-align : center; } .button { background : Menu; top : auto; left : auto; position : absolute; font-size : 12; height : 20; z-index : 0; width : 120; border : thin outset; text-align : center; cursor : NW-resize; } .preset { top : auto; left : 270; position : absolute; font-size : 0; height : 15; z-index : 0; width : 15; border : thin inset; text-align : center; } .slider_box{ top: auto; left : auto; position : absolute; }</style> <!--第二步:再将下列代码复制到<body></body>之间:--> <BODY onload="cur=test; set()"> <div><h1><font size="5"><font color="#FFFF00">十六进制</font><font color="#FF0000">R</font><font color="#008000">G</font><font color="#0000FF">B</font><font color="#FFFF00">色码转换器</font></font></h1></div> <span id="test" class="large_box"></span> <span id="R_value" class="slider" align="left" onclick="setColor('R')">R</span> <span id="R_slider" class="slider_bar" value="R" onmouseDown="curD=this; dragging=true; start_drag(); this.style.background='white'" onMouseUp="this.style.background='menu'"></span> <span id="rUp" class="small_box"></span> <span id="G_value" class="slider" align="left" onclick="setColor('G')">G</span> <span id="G_slider" class="slider_bar" value="G" onmouseDown="curD=this; dragging=true; start_drag(); this.style.background='white'" onMouseUp="this.style.background='menu'"></span> <span id="gUp" class="small_box"></span> <span id="B_value" class="slider" align="left" onclick="setColor('B')">B</span> <span id="B_slider" class="slider_bar" value="B" onmouseDown="curD=this; dragging=true; start_drag(); this.style.background='white'" onMouseUp="this.style.background='menu'"></span> <span id="bUp" class="small_box"></span> <input size=7 maxlength="7" name="hex_color"> <span class="button" onClick="setFromHex()" onmouseDown="this.style.borderStyle='inset'" onmouseUp="this.style.borderStyle='outset'">转换</span> <body> </body> </html>[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]