Jquery中文网 www.jquerycn.cn
Jquery中文网 >  CSS教程  >  经典实例  >  正文 火狐和ie中获得背景色问题(getComputedStyle与currentStyle的区别)

火狐和ie中获得背景色问题(getComputedStyle与currentStyle的区别)

发布时间:2020-05-21   编辑:www.jquerycn.cn
jquery中文网为您提供火狐和ie中获得背景色问题(getComputedStyle与currentStyle的区别) 等资源,欢迎您收藏本站,我们将为您提供最新的火狐和ie中获得背景色问题(getComputedStyle与currentStyle的区别) 资源
火狐和ie中获得背景色问题(getComputedStyle与currentStyle的区别) 火狐获得的rgbstr是rgb的因此我还要转成16进制的

function getcurrentstyle(oelement) {
if(navigator.useragent.indexof("firefox")>0 ){
var rgbstr=document.defaultview.getcomputedstyle(oelement,null).backgroundcolor;
var strr;
if(rgbstr.tostring().indexof('(')>0 && rgbstr.tostring().indexof(')')>0)
{
strr= rgbstr.tostring().substring(parseint(rgbstr.tostring().indexof('(') 1),rgbstr.tostring().indexof(')')).split(',');
}
return tohexcolor(strr[0],strr[1],strr[2]).substring(1);
}
else{
return oelement.currentstyle.backgroundcolor.trim().substring(1);
}
}

 

 代码如下 复制代码
function tohexcolor(r,g,b){
var hex='#';
var hexstr = '0123456789abcdef';
low = r % 16;
high = (r - low)/16;
hex =hexstr.charat(high) hexstr.charat(low);
low = g % 16;
high = (g - low)/16;
hex =hexstr.charat(high) hexstr.charat(low);
low = b % 16;
high = (b - low)/16;
hex =hexstr.charat(high) hexstr.charat(low);
return hex;
}

您可能感兴趣的文章:
火狐和ie中获得背景色问题(getComputedStyle与currentStyle的区别)
javascript 获取元素样式技巧分析
element-ui对话框可拖拽的功能如何实现?(附代码)
jquery在IE、FF浏览器的差别详细探讨
document.getElementById在IE和火狐中的区别
手把手教你的jquery CSS控制打印样式实例
解密jQuery内核 样式操作
JQuery结合CSS操作打印样式的方法
网页制作技巧之用CSS定义表单元素中的样式
重绘与重排如何使用

[关闭]