在FireFox下
...
curRow.style.backgroundColor='#ff0000';
alert(curRow.style.backgroundColor);
....
结果是RGB颜色值,为什么?如何让它保持原颜色16位(#ff0000)格式?一般编程语言都有数据类型转换函数,试试看呢?Javascript偶不熟,偶只输HTML,嘿嘿。参考以下的。
- HTML code
- <script type="text/javascript"> function MyColor(name,r,g,b){ this.name=name; this.red=r; this.green=g; this.blue=b; } MyColor.prototype.hexValue=function(){ var hR=this.red.toString(16); var hG=this.green.toString(16); var hB=this.blue.toString(16); return "#"+(this.red<16?("0"+hR):hR)+(this.green<16?("0"+hG):hG)+(this.blue<16?("0"+hB):hB); }; var CnLeiColor=new MyColor("red",255,0,0); alert(CnLeiColor.hexValue()); </script>

