XML DOM lookupPrefix() 方法
❮ 元素物件
示例
以下程式碼片段將 "books_ns.xml" 載入到 xmlDoc 中,並查詢給定名稱空間 URI 的字首。
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("book")[0];
document.getElementById("demo").innerHTML =
x.lookupPrefix("https://w3schools.tw/children/");
}
輸出
c
自己動手試一試 »
定義和用法
lookupPrefix() 方法返回當前節點上與指定名稱空間 URI 匹配的字首。
語法
elementNode.lookupPrefix(URI)
引數 | 描述 |
---|---|
URI | 必需。要查詢字首的名稱空間 URI。 |
❮ 元素物件