zoukankan      html  css  js  c++  java
  • jsp获取dom节点以及节点的文本值和参数属性值

    1.获取节点的方式:

      1)通过顶层获取节点:

        document.getElementById("");通过id获取节点的属性值。备注:如果包含多个相同ID的节点,只返回第一个节点

               document.getElementsByName("");返回一组相同name元素的数组。然后通过判断属性来确定是否为需要的节点,以radio,CheckBox为例,通过判断check的属性是否为TRUE;

        document.getElementsByTagName();通过标签名来获取数据,返回的一组相同标签的节点;

      2)通过父节点获取:

        obj.firstChild;已知节点的第一个子节点;同时可以递归使用 obj.firstchild.firstchild.firstchild....

        obj.lastChild;已知节点的最后一个节点;同时可以递归使用 obj.lastChild.lastChild.lastChild.....

           以上两种方式可以交替使用 obj.firstChild.lastChild.firstChild...

         obj.childNodes:获取已知节点的子节点数组。通过循环索引获取所需的节点。

        parentobj.children:获取已知节点的直接子节点数组。

           parentObj.getElementsByTagName():获取已知节点的指定类型的所有子节点的数组;

      3)通过临近节点查询:

        neighbourNode.previousSibling:获取已知节点的前一个节点;可以迭代使用,可以和firstchild,lastChild 混合使用。

        neighbourNode.nextSilbling:获取已知节点的下一个节点;可以迭代使用,也可以和firstchild,lastchild混合使用。

      3)通过子节点获取:

        childNode.parentNode;通过已知节点获取父节点。

    注:document方式获取:从全局查找;     document对象是window对象的一部分;

        

  • 相关阅读:
    20151104内置对象
    20151102adonet2
    20151029adonet1
    20151028c#4
    20151027c#3
    20151026c#2
    20151021c#1
    20151020sql2
    20151019sql1
    Codeforces Round #261 (Div. 2) C. Pashmak and Buses(思维+构造)
  • 原文地址:https://www.cnblogs.com/cflr/p/6513787.html
Copyright © 2011-2022 走看看