<!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 >
        <li></li>
         <li></li>
         <li></li>
         <li></li>
         <li></li>
    </ul>
</body>
</html>

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

相关文章:

  • 2022-02-03
  • 2022-12-23
  • 2022-01-20
  • 2022-02-01
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-04
  • 2022-12-23
  • 2022-01-26
  • 2021-05-18
  • 2022-12-23
  • 2021-12-30
  • 2021-11-30
相关资源
相似解决方案