zoukankan      html  css  js  c++  java
  • 火狐与ie兼容的问题总结

    刚入新公司。。。一切都在适应中。希望很快在新公司找到自己的位置。这几天遇到几个头疼的火狐与ie兼容问题整理下来:

    1:rules与cssRules区别:

    代码
    function addCSSRule(css,key,value){
         
    //var css = document.styleSheets[document.styleSheets.length-1];
         if(navigator.userAgent.indexOf("Firefox")>0 )
         {
            css.insertRule(key
    +"{"+value+"}", css.cssRules.length)
         }
         
    else
         {
            css.addRules(key,value);
         }
     
     }
     function removeCSSRule(key){
         
    for(var i = 0; i < document.styleSheets.length; i++){
             var css 
    = document.styleSheets[i];
            navigator.userAgent.indexOf(
    "Firefox")>0 ? 
                 (function(){
                     
    for(var j = 0; j < css.cssRules.length; j++){
                         
    if(css.cssRules[j].selectorText==key){
                             
                             css.deleteRule(j);
                         }
                     }
                 })() :
                 (css.removeRule(key)) ;
         }
     }

    我是这样加了一个方法解决这个问题的。。

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

    代码
      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;  
        } 

    记住 火狐获得的rgbstr是rgb的因此我还要转成16进制的。我也整理了一个很笨的转换方法再上面望打击拍砖!

    3: 火狐new Date()方法限制。

    今天发现这样的一个问题:server端传入的参数格式是这样的:2013-06-13 16:03:48是字符串类型的。我获取后直接new Date('2013-06-13 16:03:48').很遗憾的直接出错。

    原来是这样:firefox不接受这种格式的日期形式

    改成这样:即可2013/06/13 16:03:48.so  这样就简单多了:.replace(/\-/g,'/');

  • 相关阅读:
    Python(八)进程、线程、协程篇
    Python(七)Socket编程、IO多路复用、SocketServer
    Python(六)面向对象、异常处理、反射、单例模式
    Python并发编程之多进程
    ORM框架SQLAlchemy
    Python并发编程之IO模型
    Python并发编程之同步异步and阻塞非阻塞
    二分查找
    插入排序
    单向链表
  • 原文地址:https://www.cnblogs.com/blueSkys/p/1780512.html
Copyright © 2011-2022 走看看