javascript之DOM對象,javascriptdom

來源:互聯網
上載者:User

javascript之DOM對象,javascriptdom

document方法

document.createElement(Tag) :建立一個html標籤對象

document.getElementById(ID) :獲得指定ID值的對象

document.getElementsByName(Name)//獲得指定Name值的對象

getElementsByTagName(tagName):返迴文檔中指定標記名的所有Element節點,返回一個節點列表(可看成數組)

getElementByClassName(className):返迴文檔中指定樣式名的所有Element節點,返回一個節點列表(可看成數組)

createTextNode(text):建立一個包含靜態文本text的文本節點

createAttribute():用指定的名字建立新的Attr節點

createComment():用指定的字串建立新的comment節點

節點(node)的常用屬性

nodeType :節點的類型

nodeName :節點的名稱

nodeValue :節點值

innerHTML :返回節點內的所有內容

parentNode :返回當前節點的父節點,如果沒有父節點,則返回null

childNodes :返回當前節點的所有子節點,以數組形式存放,如果沒有子節點則返回空數組

firstChild :返回當前節點的第一個子節點。如果沒有子節點,則返回null

lastChild :返回當前節點的最後一個子節點,如果沒有子節點,則返回null

nextSibling  :返回當前節點的下一個兄弟節點

previousSibing :返回當前節點的上一個兄弟節點

attributes :如果該節點是一個Element節點,則以nameNodeMap形式返回該元素的屬性

節點方法

removeChild(childNode):從元素中刪除指定的子項目

append(childNode):將指定的節點(childNode)增加到當前元素的子節點列表最後(作為一個新的子節點)

insertBefore(newNode,targetNode):將節點newNode作為當前元素的子節點插入到targetNode子節點元素的前面

replaceChild(newNode,oldNode):將節點oldNode替換為節點newNode

cloneNode(true) :複製當前節點,true表示複製當前節點以及它的所有子孫節點

hasChildNodes() :該方法返回一個布爾值,指示元素是否有子項目

getAttribute(name,value)  :獲得元素中的name屬性的值

setAttribute(name,value):設定元素中的name屬性的值

removeAttribute(name):從元素中刪除屬性name

hasAttribute(name):返回該素是否具有指定name名字的屬性,如果有,則返回true

getAttributeNode()  :以Attr節點的形式返回指定的屬性的值

setAttributeNode()  :把指定的Attr節點添加到該元素的列表中

removeAttributeNode():從元素的屬性列表中刪除指定的Attr節點

getNamedItem() : 返回指定的節點。常與attributes屬性結合使用



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.