zoukankan      html  css  js  c++  java
  • dom节点相关问题

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>dom节点</title>
    <script type="text/javascript">
    window.onload = function(){
        var oUl = document.getElementsByTagName('ul')[0];
        // alert(oUl.childNodes.length)    // 7
        // alert(oUl.children.length)// 3  children 实际上是指的元素节点
        var oLi = document.getElementById('two');
        alert(oLi.parentNode)  
        // nodeType 1是指元素节点  3是指文本节点;
        alert(oLi.parentNode.nodeType) //1
        alert(oUl.firstChild.nodeType) //3
        alert(oLi.nextSibling.nodeType)// 3
        alert(oLi.nextElementSibling.nodeType )//  1 不兼容的情况下可以试试nextElementSibling.nodeType,一般情况下是可以的。  
        
     }
    </script>
    </head>
    <body>
        <ul>
            <li>111111</li>
            <li id="two">46343</li>
            <li>3333</li>
        </ul>
    </body>
    </html>

  • 相关阅读:
    常用英语1000句
    TXT EXPLORER
    窗体美化
    C++ Code_StatusBar
    C++ Code_Slider
    C++ Code_ScrollBar
    C++ Code_ImageList
    C++ Code_HotKey
    C++ Code_animateCtrl
    C++ CheckMenuItem
  • 原文地址:https://www.cnblogs.com/yangwenlong/p/10723957.html
Copyright © 2011-2022 走看看