Html 颜色选择器,支持返回RGB值与Html颜色值

本文介绍了一款Office风格的颜色选择器实现方案,该选择器通过JavaScript编写,支持多种颜色预设,并提供了一个‘其它颜色’的功能选项,允许用户自定义颜色。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果如图:
None.gif<HTML>
None.gif
<HEAD>
None.gif
<TITLE> Office 风格颜色选择器</TITLE>
None.gif
<META NAME="Generator" CONTENT="EditPlus">
None.gif
<META NAME="Author" CONTENT="">
None.gif
<META NAME="Keywords" CONTENT="">
None.gif
<META NAME="Description" CONTENT="">
None.gif
</HEAD>
None.gif
None.gif
<BODY>
ExpandedBlockStart.gifContractedBlock.gif
<script language=javascript>dot.gif
InBlock.gif
<!--
InBlock.gif
InBlock.gif
//夜狼制作 OFFICE风格的色彩选择器
InBlock.gif

InBlock.gif
//注意:只有把<script></script>标签放在<body>标签内才可以正常使用“其它颜色dot.gif”功能
InBlock.gif

InBlock.gifdocument.write(
"<OBJECT id=\"dlgHelper\" CLASSID=\"clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b\" width=\"0px\" height=\"0px\"></OBJECT>");
InBlock.gif
var ocolorPopup = window.createPopup();
InBlock.gif
var ecolorPopup=null;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
function colordialogmouseout(obj)dot.gif{
InBlock.gif    obj.style.borderColor
="";
InBlock.gif    obj.bgColor
="";
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
function colordialogmouseover(obj)dot.gif{
InBlock.gif    obj.style.borderColor
="#0A66EE";
InBlock.gif    obj.bgColor
="#EEEEEE";
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
function colordialogmousedown(color)dot.gif{
InBlock.gif    ecolorPopup.value
=color;
InBlock.gif    
//document.body.bgColor=color;
InBlock.gif
    ocolorPopup.document.body.blur();
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
function colordialogmore()dot.gif{
InBlock.gif    
var sColor=dlgHelper.ChooseColorDlg(ecolorPopup.value);
InBlock.gif    sColor 
= sColor.toString(16);
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if (sColor.length < 6dot.gif{
InBlock.gif        
var sTempString = "000000".substring(0,6-sColor.length);
InBlock.gif        sColor 
= sTempString.concat(sColor);
ExpandedSubBlockEnd.gif    }

InBlock.gif    ecolorPopup.value
="#"+sColor.toUpperCase();
InBlock.gif    
//document.body.bgColor="#"+sColor.toUpperCase();
InBlock.gif
    ocolorPopup.document.body.blur();
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
function colordialog()dot.gif{
InBlock.gif    
var e=event.srcElement;
InBlock.gif    e.onkeyup
=colordialog;
InBlock.gif    ecolorPopup
=e;
InBlock.gif    
var ocbody;
InBlock.gif    
var oPopBody = ocolorPopup.document.body;
InBlock.gif    
var colorlist=new Array(40);
InBlock.gif    oPopBody.style.backgroundColor 
= "#f9f8f7";
InBlock.gif    oPopBody.style.border 
= "solid #999999 1px";
InBlock.gif    oPopBody.style.fontSize 
= "12px";
InBlock.gif
InBlock.gif    colorlist[
0]="#000000";    colorlist[1]="#993300";    colorlist[2]="#333300";    colorlist[3]="#003300";
InBlock.gif    colorlist[
4]="#003366";    colorlist[5]="#000080";    colorlist[6]="#333399";    colorlist[7]="#333333";
InBlock.gif
InBlock.gif    colorlist[
8]="#800000";    colorlist[9]="#FF6600";    colorlist[10]="#808000";colorlist[11]="#008000";
InBlock.gif    colorlist[
12]="#008080";colorlist[13]="#0000FF";colorlist[14]="#666699";colorlist[15]="#808080";
InBlock.gif
InBlock.gif    colorlist[
16]="#FF0000";colorlist[17]="#FF9900";colorlist[18]="#99CC00";colorlist[19]="#339966";
InBlock.gif    colorlist[
20]="#33CCCC";colorlist[21]="#3366FF";colorlist[22]="#800080";colorlist[23]="#999999";
InBlock.gif
InBlock.gif    colorlist[
24]="#FF00FF";colorlist[25]="#FFCC00";colorlist[26]="#FFFF00";colorlist[27]="#00FF00";
InBlock.gif    colorlist[
28]="#00FFFF";colorlist[29]="#00CCFF";colorlist[30]="#993366";colorlist[31]="#CCCCCC";
InBlock.gif
InBlock.gif    colorlist[
32]="#FF99CC";colorlist[33]="#FFCC99";colorlist[34]="#FFFF99";colorlist[35]="#CCFFCC";
InBlock.gif    colorlist[
36]="#CCFFFF";colorlist[37]="#99CCFF";colorlist[38]="#CC99FF";colorlist[39]="#FFFFFF";
InBlock.gif
InBlock.gif    ocbody 
= "";
InBlock.gif    ocbody 
+= "<table CELLPADDING=0 CELLSPACING=3>";
InBlock.gif    ocbody 
+= "<tr height=\"20\" width=\"20\"><td align=\"center\"><table style=\"border:1px solid #808080;\" width=\"12\" height=\"12\" bgcolor=\""+e.value+"\"><tr><td></td></tr></table></td><td bgcolor=\"eeeeee\" colspan=\"7\" style=\"font-size:12px;\" align=\"center\">当前颜色</td></tr>";
ExpandedSubBlockStart.gifContractedSubBlock.gif    
for(var i=0;i<colorlist.length;i++)dot.gif{
InBlock.gif        
if(i%8==0)
InBlock.gif            ocbody 
+= "<tr>";
InBlock.gif        ocbody 
+= "<td width=\"14\" height=\"16\" style=\"border:1px solid;\" onMouseOut=\"parent.colordialogmouseout(this);\" onMouseOver=\"parent.colordialogmouseover(this);\" onMouseDown=\"parent.colordialogmousedown('"+colorlist[i]+"')\" align=\"center\" valign=\"middle\"><table style=\"border:1px solid #808080;\" width=\"12\" height=\"12\" bgcolor=\""+colorlist[i]+"\"><tr><td></td></tr></table></td>";
InBlock.gif        
if(i%8==7)
InBlock.gif            ocbody 
+= "</tr>";
ExpandedSubBlockEnd.gif    }

InBlock.gif    ocbody 
+= "<tr><td align=\"center\" height=\"22\" colspan=\"8\" onMouseOut=\"parent.colordialogmouseout(this);\" onMouseOver=\"parent.colordialogmouseover(this);\" style=\"border:1px solid;font-size:12px;cursor:default;\" onMouseDown=\"parent.colordialogmore()\">其它颜色dot.gif</td></tr>";
InBlock.gif    ocbody 
+= "</table>";
InBlock.gif
InBlock.gif    oPopBody.innerHTML
=ocbody;
InBlock.gif    ocolorPopup.show(e.offsetLeft, e.offsetTop
+e.offsetHeight, 158147, document.body);
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif
//-->
None.gif
</script>
None.gif选择颜色:
<input name="sel1" type="text" onfocus="colordialog()"></BODY>
None.gif
</HTML>
None.gif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值