zoukankan      html  css  js  c++  java
  • javascript 操作节点的属性

    使用层次关系访问节点

    parentNode:返回节点的父节点

    childNodes:返回子节点集合,childNodes[i]

    firstChild:返回节点的第一个子节点,最普遍的用法是访问该元素的文本节点

    firstElementChild:返回节点的第一个元素节点

    lastChild:返回节点的最后一个子节点

    lastElementChild:返回节点的最后一个子节点的元素节点

    nextSibling:下一个节点

    previousSibling:上一个节点

    setAttribute()设置某个节点的属性值

      节点对象.setAttribute("属性名","属性值")

    getAttribute()获取某个节点的属性值

      节点对象.getAttribute("属性名")

    例如:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>node节点</title>
    </head>
    <script>
      onload=function(){
        var node1=document.getElementsByTagName("ul")[0];
        //console.log(node1.childNodes);
        node1.setAttribute("xxyy","1122")
        console.log(node1.firstElementChild.getAttribute("xxyy"));
      }
    </script>

    <body>
      <ul>
        <li id="a" xxyy="ooxx">asdf</li>
        <li id="b"></li>
        <li id="c"></li>
      </ul>
    </body>
    </html>

  • 相关阅读:
    poj_3923Ugly Windows
    背包问题九讲笔记_01背包
    素数环
    全排列的STL实现
    [1424] 金克拉与贪吃蛇的故事
    hdoj_1548A strange lift
    iBATIS缓存配置详解
    jQuery的一些特性和用法:
    当iBATIS出项某个列不存在的问题
    当iBATIS出项某个列不存在的问题
  • 原文地址:https://www.cnblogs.com/i1991/p/7161387.html
Copyright © 2011-2022 走看看