• 节点的层次关系


    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="utf-8">

    <title></title>

    <script type="text/javascript" src="new_file.js"></script>

    </head>

    <body>

    <input type="radio" name="" /><input type="text" name="" /><div id="box">

    <span>我是span1</span>

    <span>我是span2</span></div><input type="text" name="" />

    <script type="text/javascript">

     

    // 怎么获取前面所有的兄弟元素??????

     

     

    var oDiv = $("box");

    // 1.获取所有的子节点 childNodes

    console.log( oDiv.innerText );

    // 2.获取第一个子节点 firstChild

    console.log( oDiv.firstChild );

    // 3.获取最后一个子节点 lastChild

    console.log( oDiv.lastChild );

    // 4.获取父节点  parentNode

    console.log( oDiv.parentNode );

     

    ////////////////兄弟关系/////////////////

    // 5.获取前一个兄弟节点  previousSibling

    console.log( oDiv.previousSibling );

    // 6.获取下一个兄弟节点  nextSibling

    console.log( oDiv.nextSibling );

     

    ///////////////////根节点/////////////////

    console.log( oDiv.ownerDocument );

     

     

    </script>

    </body>

    </html>

  • 相关阅读:
    【js】数据表格开启同比化显示,增加对比性
    Kotlin 使用协程编写高效的并发程序
    Kotlin泛型的高级特性
    kotlin基础
    Java接口和抽象类区别
    Java内存泄漏
    jmeter,注意:您可以通过定义属性resultcollector.action_if_file_exists来避免这个弹出框
    性能测试术语
    jenkins正常显示jmeter的html报告设置
    jmeter: beanshell后置处理程序,清空文件和保存json提取器提取的数据到文件中
  • 原文地址:https://www.cnblogs.com/d-z-j-boke/p/9621506.html
Copyright © 2020-2023  润新知