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屬性結合使用