XML DOM getAttributeNode() 方法
Element 對象
定義和用法
getAttributeNode() 方法從當(dāng)前元素中通過名稱取得屬性節(jié)點。
語法
elementNode.getAttributeNode(name)
參數(shù) | 描述 |
name | 必需。規(guī)定要獲取的屬性節(jié)點。 |
實例
下面的代碼片段使用 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("
");
}
輸出:
category = COOKING
category = CHILDREN
category = WEB
category = WEB
嘗試一下 ?
Element 對象
更多建議: