XML DOM getAttribute() 方法


Element 對象參考手冊 Element 對象

定義和用法

getAttribute() 方法根據名稱取得屬性值。

語法

elementNode.getAttribute(name)

參數 描述
name 必需。規定從中獲取屬性值的屬性。


實例

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

實例

xmlDoc=loadXMLDoc("books.xml"); x=xmlDoc.getElementsByTagName('book'); for (i=0;i<x.length;i++) { document.write(x[i].getAttribute('category')); document.write("<br>"); }

輸出:

COOKING
CHILDREN
WEB
WEB


Element 對象參考手冊 Element 對象