关于在FireFox下的style.backgroundColor 值,急!

gzcat 2007-12-17 05:45:03
在FireFox下
...
curRow.style.backgroundColor='#ff0000';
alert(curRow.style.backgroundColor);
....

结果是RGB颜色值,为什么?如何让它保持原颜色16位(#ff0000)格式?
...全文
233 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
浴火_凤凰 2008-06-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 nicholsky 的回复:]
参考以下的。

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);
};

[/Quote]
楼主高手啊!!!!!
iscandy 2008-06-10
  • 打赏
  • 举报
回复
想不到 Javascript 的 function 居然可以这样用,鬼斧神工!
nicholsky 2007-12-18
  • 打赏
  • 举报
回复
参考以下的。
<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>
bsdshen 2007-12-17
  • 打赏
  • 举报
回复
一般编程语言都有数据类型转换函数,试试看呢?Javascript偶不熟,偶只输HTML,嘿嘿。

61,112

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧