XML DOM getAttributeNode() 方法


Element 對象參考手冊 Element 對象

定義和用法

getAttributeNode() 方法從當前元素中通過名稱取得屬性節點。

語法

elementNode.getAttributeNode(name)

參數 描述
name 必需。規定要獲取的屬性節點。


實例

下麵的代碼片段使用 loadXMLDoc() 把 "books.xml" 載入 xmlDoc 中,並從所有的 <book> 元素中取得 "category" 屬性:

實例

xmlDoc=loadXMLDoc("books.xml"); x=xmlDoc.getElementsByTagName('book'); for(i=0;i<x.length;i++) { attnode=x.item(i).getAttributeNode("category"); document.write(attnode.name); document.write(" = "); document.write(attnode.value); document.write("<br>"); }

輸出:

category = COOKING
category = CHILDREN
category = WEB
category = WEB


Element 對象參考手冊 Element 對象