XML DOM getAttribute() 方法
Element 對(duì)象
定義和用法
getAttribute() 方法根據(jù)名稱取得屬性值。
語(yǔ)法
elementNode.getAttribute(name)
參數(shù) | 描述 |
name | 必需。規(guī)定從中獲取屬性值的屬性。 |
實(shí)例
下面的代碼片段使用 loadXMLDoc() 把 "books.xml" 載入 xmlDoc 中,并取得所有 <book> 元素中的 "category" 屬性的值:
實(shí)例
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 對(duì)象
更多建議: