XML DOM baseURI 屬性
❮ Node 物件
示例
下面的程式碼片段載入 "books_ns.xml" 到 xmlDoc 中,並返回 <title> 元素的 base 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 x, i, xmlDoc, txt;
xmlDoc = xml.responseXML;
txt = "";
x = xmlDoc.getElementsByTagName("title");
for (i = 0; i < x.length; i++) {
txt += "Base URI: " + x.item(i).baseURI + "<br>";
}
document.getElementById("demo").innerHTML = txt;
}
上面程式碼的輸出將是
Base URI: https://w3schools.tw/xml/books_ns.xml
Base URI: https://w3schools.tw/xml/books_ns.xml
自己動手試一試 »
定義和用法
baseURI 屬性返回節點的絕對基礎 URI。
瀏覽器支援
baseURI 屬性在所有主要瀏覽器中都受支援,但 Internet Explorer 除外。
語法
nodeObject.baseURI
技術詳情
返回值 | 一個字串,表示節點的絕對基礎 URI |
---|---|
DOM 版本 | Core Level 3 節點物件 |
❮ Node 物件