zoukankan      html  css  js  c++  java
  • Javascript 中判断是谷歌浏览器和IE浏览器的方法

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <style type="text/css"></style>
        <script type="text/javascript">
            window.onload = function () {
                var oUl = document.getElementById("ul1");
                if (oUl.firstElementChild) {
                    //谷歌浏览器
                    oUl.firstElementChild.style.background = "red";
                }
                if (oUl.firstChild) {
                    //IE 浏览器
                    oUl.firstChild.style.background = "red";
                }
            }
        </script>
    </head>
    <body>
        <ul id="ul1">
            <li></li>
             <li></li>
             <li></li>
             <li></li>
             <li></li>
        </ul>
    </body>
    </html>
    

    IE 有firstChild所以是true,相反的,谷歌没有,会返回undifined

  • 相关阅读:
    C#windows向窗体传递泛型类
    phoenix与spark整合
    phoenix创建二级索引
    git
    socket详解
    切片
    通过串口读写数据
    Python 跳出多重循环
    Python从json中提取数据
    Python 字典
  • 原文地址:https://www.cnblogs.com/alphafly/p/3763873.html
Copyright © 2011-2022 走看看