• 兼容性问题总结


    1、event兼容性写法   var ev=ev||window.event

    2、clientWidth 兼容写法

    document.documentElement.clientWidth||document.body.clientWidth

    3、ev.target  Var target=ev.srcElement||ev.target

    4、var scrollTop = windows.scrollTop || document.documentElement.scrollTop

    5、ajax兼容性

    if (window.XMLHttpRequest) {

            //IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码

            xmlhttp = new XMLHttpRequest();

        } else {

            //IE6, IE5 浏览器代码

            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

    }

    5、获取属性兼容性

    if (window.getComputedStyle) {

            //标准流

            console.log(window.getComputedStyle(div1).width);

            console.log(window.getComputedStyle(div1).cssFloat);

        } else {

            //IE兼容

            console.log(div1.currentStyle.styleFloat);

    }

    6、绑定事件的兼容性

    //绑定点击事件 解决兼容性

        if(window.addEventListener){

            div1 = addEventListener("click",function(){console.log(123)})

        }else{

            //处理IE兼容

            div1.attachEvent("onclick",function(){console.log(123)})

    }

    7、阻止事件冒泡的兼容性

    if(document.all){  //只有ie识别
            e.cancelBubble=true;
        }else{
            e.stopPropagation();
        }

    8、阻止默认事件

    (1)ev.preventDefault(); (2)IE兼容写法 e.returnValue = false;

    9、标签兼容性问题

    <!--[ifltIE9]>

    <scriptsrc="//cdn.bootcss.com/respond.js/1.4.2/respond.js"></script>

    <scriptsrc="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>

    <![endif]-->

    html5shiv.min.js:处理IE9以下的对于html5标签的兼容性问题

    respond.js:处理css3兼容性问题

  • 相关阅读:
    mfc中的_T
    zmq的send
    c++内存相关函数
    如何运行linux shell程序
    Dockfile中的命令如何在.sh中执行
    Linux 错误: $' ': command not found
    实战ZeroMQ的PUSH/PULL推拉模式
    Servlet笔记
    进程控制块(PCB)
    Makefile规则介绍
  • 原文地址:https://www.cnblogs.com/wangxue13/p/13521375.html
Copyright © 2020-2023  润新知