js原生dom方法總結

來源:互聯網
上載者:User

標籤:支援   lis   des   number   點列   create   stc   bsp   nts   

1.document

document方法
getElementById (Node)返回指定節點的引用
getElementsByTagName (NodeList)返迴文檔中所有匹配元素的集合
querySelector (Node)返回與選取器匹配的首個節點 (ie8+)
querySelectorAll (Node)返回與選取器匹配的所有節點 (ie8+),其中ie8中選取器只支援css2選取器
createElement(name) (Node)返回建立的節點
createTextNode(text) (Node)返回建立的文本節點
documentElement (Node)返回html節點
body (Node)返回body節點
createDocumentFragment (Node)返回一個DocumentFragment類型的節點,用作一個輕量版本的 Document 使用,用於儲存已排好版的或尚未打理好格式的XML片段。

2.node(包括element,text,attribute,document,comment等,Element只是nodeType=1時node)

node方法
appendChild(node) 添加一個子節點
removeChild(node) 移除一個子節點
replaceChilde(node) 替換一個子節點
insertBefore(newNode,refNode) 在同一層級的節點前面插入新節點
hasChildNodes() (Boolean)返回是否子節點
cloneNode(bDeep) (Node)返回節點的副本,bDeep表示是否複製其子節點

node屬性
nodeName (String)節點名稱
nodeType (Number)節點類型
nodeValue (String)節點的值
parentNode (Node)父節點的引用
childNodes (NodeList)子節點的列表
firstChild (Node)首個子節點
lastChild (Node)最後一個子節點
previouSibling (Node)前一個兄弟節點
nextSibling (Node)後一個子節點

3.element(可以有屬性和子節點的node,對應XML中的一個tag元素,繼承自node)

element方法
getAttribute(attrName) (string)返回屬性的value
setAttribute(attrName,value) (string)給屬性賦值
removeAttribue(attrName) (string)刪除指定屬性
getElementsByTagName(name) (NodeList)返回指定tag的節點列表
querySelector (Node)(ie9+)
querySelectorAll (NodeList)(ie8+)(:scope pseudo-class 不支援)

element屬性
children (elementList)返回子項目列表(與子節點有區別,ie9+正確,ie6-8錯誤的包含Comment類型節點)

 

 

js原生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.