<script type= "Text/javascript" >//title: Determine whether the two color values are similar colors//author:cnlei te:http://www.cnlei.com//Real application, please comment out or remove the alert () prompt (Issimilarcolor) function (shexcolora,shexcolorb,noffset ) {this.offsetnum=math.abs (noffset); this.offsetnum>255?this.offsetnum=this.offsetnum-256: ""; var arrnuma=[parseint (shexcolora.substring (0,2), parseint (shexcolora.substring (2,4),), parseint (SHex Colora.substring (4,6), 16)]; var arrnumb=[parseint (shexcolorb.substring (0,2), parseint (shexcolorb.substring (2,4),), parseint (SHex Colorb.substring (4,6), 16)]; for (Var i=0;i<arrnuma.length;i++) {if (Math.Abs (arrnuma[i]-arrnumb[i)) >this.offsetnum) { Alert ("+i+" is not the same as the difference is: "+ (Arrnuma[i]-arrnumb[i]) +", \ n exceeded the maximum error: "+this.offsetnum); return false; }; Alert ("Similar color \ n" +shexcolora+ "\ n" +shexcolorb) return true; } issimilarcolor ("FFFFFF", "F0fffe", 10); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]