jsp擷取dom節點以及節點的文本值和參數屬性值

來源:互聯網
上載者:User

標籤:bsp   ast   nts   簽名   window   參數   style   判斷   取數   

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對象的一部分;

 

 

    

jsp擷取dom節點以及節點的文本值和參數屬性值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.