XML DOM getAttributeNS() 方法
❮ 元素物件
示例
以下程式碼片段將 "books_ns.xml" 載入到 xmlDoc 中,並獲取第一個 <title> 元素的 "lang" 屬性值
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books_ns.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x = xmlDoc.getElementsByTagName("title")[0];
var ns = "https://w3schools.tw/children/";
document.getElementById("demo").innerHTML =
x.getAttributeNS(ns, "lang");
}
輸出
en
自己動手試一試 »
定義和用法
getAttributeNS() 方法透過名稱空間 URI 和名稱獲取屬性值。
語法
elementNode.getAttributeNS(ns,name)
引數 | 描述 |
---|---|
ns | 必需。指定要從中獲取屬性值的名稱空間 URI |
name | 必需。指定要從中獲取屬性值的屬性 |
❮ 元素物件