DIV CSS 佈局教程網

JavaScript 節點知識詳解
編輯:JavaScript基礎知識     

節點常用屬性

childNodes 提供子節點清單,firstChild 與 lastChild 取得首尾子節點,nextSibling 與 previousSibling 取得兄弟節點,parentNode 取得父節點,nodeType 與 nodeName 判斷節點類型與名稱,nodeValue 與 text 可讀寫文字內容。

節點常用方法

appendChild 新增子節點,insertBefore 插入到指定節點前,removeChild 刪除子節點,replaceChild 取代子節點,cloneNode 複製節點,createElement 與 createTextNode 建立元素與文字節點。

DOM 樹與存取

文件可視為樹狀結構。document.documentElement 是根節點,document.body 是主體。絕對存取可用 getElementById,相對存取可用 parentNode、childNodes、firstChild、lastChild、nextSibling、previousSibling。

操作節點

新增元素時,先 createElement,再 appendChild 或 insertBefore。刪除時,通常從父節點呼叫 removeChild。複製時,cloneNode 的參數可決定是否包含子節點。

XML 應用

在 XML DOM 中,還可用 createNode、createAttribute、createCDATASection、createComment、selectNodes、selectSingleNode 等方法建立與查詢節點。實際使用時,仍應注意瀏覽器與文件型別差異。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved