<div class="htmlarea"> <textarea id="runcode95089"> <script type="text/javascript"> //Title : 判断两种颜色值是否为相似颜色 //Author : CnLei //WebSite : http://www.cnlei.com //真正应用时,请将alert()提示信息注释掉或删除掉 function isSimilarColor(sHexColorA,sHexColorB,nOffset){ this.offsetNum=Math.abs(nOffset); this.offsetNum>255?this.offsetNum=this.offsetNum-256:""; var arrNumA=[parseInt(sHexColorA.substring(0,2),16), parseInt(sHexColorA.substring(2,4),16), parseInt(sHexColorA.substring(4,6),16)]; var arrNumB=[parseInt(sHexColorB.substring(0,2),16), parseInt(sHexColorB.substring(2,4),16), parseInt(sHexColorB.substring(4,6),16)]; for (var i=0;i<arrNumA.length;i++){ if(Math.abs(arrNumA[i]-arrNumB[i])>this.offsetNum){ alert("不相似 第"+i+"组的差值为:"+(arrNumA[i]-arrNumB[i])+",\n超过了最大误差:"+this.offsetNum); return false; }; } alert("相似色 "+sHexColorA+"\n"+sHexColorB) return true; } isSimilarColor("FFFFFF","F0FFFE",10); </script> </textarea><br><input onclick="runEx('runcode95089')" type="button" value="运行代码"> <input onclick="doCopy('runcode95089')" type="button" value="复制代码"> <input onclick="doSave(runcode95089)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>