XML DOM getAttributeNS() 方法
Element 對象
定義和用法
getAttributeNS() 方法通過命名空間 URI 和名稱取得屬性值。
語法
elementNode.getAttributeNS(ns,name)
參數(shù) | 描述 |
ns | 必需。規(guī)定從中獲取屬性值的命名空間 URI。 |
name | 必需。規(guī)定從中獲取屬性值的屬性。 |
實例
下面的代碼片段使用 loadXMLDoc() 把 "books_ns.xml" 載入 xmlDoc 中,創(chuàng)建一個新的 <book> 節(jié)點,并從第一個 <title> 元素中取得 "lang" 屬性值:
實例
xmlDoc=loadXMLDoc("books_ns.xml");
x=xmlDoc.getElementsByTagName("title")[0];
ns="//www.o2fo.com/children/";
document.write(x.getAttributeNS(ns,"lang"));
輸出:
en
嘗試一下 ?
Element 對象
更多建議: