HTML DOM baseURI 属性

htmlweb developmentfront end technology更新于 2025/9/21 15:40:17

HTML DOM baseURI 属性返回文档的基本统一资源标识符 (URI)。该属性为只读属性。返回类型为字符串值,表示给定页面的基本 URI。

语法

以下是 baseURI 属性的语法 −

node.baseURI

示例

让我们看一个 HTML DOM baseURI 属性的示例 −

<!DOCTYPE html>
<html>
<body>
<p>Click the button below to see the base URI of the document</p>
<button onclick="BaseFunction()">BASE URI</button>
<p id="Sample"></p>
<script>
   function BaseFunction() {
      var x = document.baseURI;
      document.getElementById("Sample").innerHTML = x;
   }
</script>
</body>
</html>

输出

这将产生以下输出 −

点击 BASE URI 按钮 −

在上面的例子中 −

我们创建了一个按钮 BASE URI 来执行 BaseFunction() −

<button onclick="BaseFunction()">BASE URI</button>

BaseFunction() 使用 baseURI 属性获取文档的 baseURI,并将其显示在 id 为"Sample"的段落中 −

function BaseFunction() {
   var x = document.baseURI;
   document.getElementById("Sample").innerHTML = x;
}

相关文章


有用资源