zoukankan      html  css  js  c++  java
  • js中元素结点的引用

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript">

    function getDom01(){
    //var divs = document.querySelectorAll("#box > div");
    //var div = document.querySelector("#box1");
    //得到子节点 和父节点
    //得到父节点 level by level
    var div = document.getElementById("box1");
    var p = div.parentNode;
    console.log(div);
    console.log(p);

    //得到子节点
    var c = div.childNodes;
    /* for(var i=0; i<c.length;i++){
    console.log(c[i].nodeName);
    }*/

    var pre = div.previousSibling;
    console.log(pre);
    var next = div.nextSibling;
    console.log(next);
    }
    </script>
    </head>
    <body>
    <input type="button" onclick="getDom01()" value="getDom01">
    <hr>
    <div id="box">
    <div id="box1">
    <span>this is a span in div 01</span>
    <span>this is a span in div 02</span>
    </div><div id="box2">
    <span>this is a span in div 01</span>
    <span>this is a span in div 02</span>
    </div>
    <div id="box3">
    <span>this is a span in div 01</span>
    <span>this is a span in div 02</span>
    </div>
    <div id="box4">
    <span>this is a span in div 01</span>
    <span>this is a span in div 02</span>
    </div>
    </div>
    </body>
    </html>
  • 相关阅读:
    PDO应用
    分页查询
    PHP去除数组中重复数据的两个例子
    数据库访问(现用基本格式)
    克隆、加载类
    抽象类和接口
    静态
    PHP基础
    数据库的常用函数
    数据库的高级查询
  • 原文地址:https://www.cnblogs.com/hwgok/p/5734089.html
Copyright © 2011-2022 走看看