firefox火狐浏览器与与ie兼容的2个问题总结
浏览器 问题 总结 兼容 IE firefox 火狐
2023-06-13 09:14:23 时间
1:rules与cssRules区别:
复制代码代码如下:
functionaddCSSRule(css,key,value){
//varcss=document.styleSheets[document.styleSheets.length-1];
if(navigator.userAgent.indexOf("Firefox")>0)
{
css.insertRule(key+"{"+value+"}",css.cssRules.length)
}
else
{
css.addRules(key,value);
}
}
functionremoveCSSRule(key){
for(vari=0;i<document.styleSheets.length;i++){
varcss=document.styleSheets[i];
navigator.userAgent.indexOf("Firefox")>0?
(function(){
for(varj=0;j<css.cssRules.length;j++){
if(css.cssRules[j].selectorText==key){
css.deleteRule(j);
}
}
})():
(css.removeRule(key));
}
}
我是这样加了一个方法解决这个问题的。。
2:火狐和ie中获得背景色问题(getComputedStyle与currentStyle的区别)
functiongetCurrentStyle(oElement){
if(navigator.userAgent.indexOf("Firefox")>0){
varrgbstr=document.defaultView.getComputedStyle(oElement,null).backgroundColor;
varstrR;
if(rgbstr.toString().indexOf("(")>0&&rgbstr.toString().indexOf(")")>0)
{
strR=rgbstr.toString().substring(parseInt(rgbstr.toString().indexOf("(")+1),rgbstr.toString().indexOf(")")).split(",");
}
returntoHexColor(strR[0],strR[1],strR[2]).substring(1);
}
else{
returnoElement.currentStyle.backgroundColor.trim().substring(1);
}
}
functiontoHexColor(r,g,b){
varhex="#";
varhexStr="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);
returnhex;
}
记住火狐获得的rgbstr是rgb的因此我还要转成16进制的。我也整理了一个很笨的转换方法再上面望打击拍砖!
相关文章
- 浏览器刷新一次,nginx执行2次的问题
- 谷歌浏览器搜索使用指南[通俗易懂]
- 阶段七:浏览器安全
- 主流浏览器图片反防盗链方法总结
- 面试官:你懂 HTTP 缓存,那说下浏览器强制刷新是怎么实现的?
- Selenium自动化chrome驱动版本匹配但是调用浏览器失败:Only local connections are allowed. 问题解决
- 禁止浏览器刷新(使用jqeury完成)详解编程语言
- 空格 在不同浏览器中显示距离不一致问题解决方法详解编程语言
- 谷歌浏览器发布v79.0.3945.88正式版修复漏洞和安卓版的数据丢失问题
- UC 浏览器最大的问题
- 浏览器无法运行JAVA脚本的解决方法
- 关于B/S判断浏览器断开的问题讨论
- 关于Mozilla浏览器不支持innerText的解决办法
- jQuery获取CSS样式中的颜色值的问题,不同浏览器格式不同的解决办法
- 用PHP实现浏览器点击下载TXT文档的方法详解
- 讨论html与javascript在浏览器中的加载顺序问题
- 浅析jQuery中调用ajax方法时在不同浏览器中遇到的问题
- 使用jQuery不判断浏览器高度解决iframe自适应高度问题
- 通过js为元素添加多项样式,浏览器全兼容写法