HTMLTitleElement: text 屬性
HTMLTitleElement 介面的 text 屬性將文件標題的子文字內容表示為一個字串。它包含 <title> 元素的文字內容;如果 <title> 元素中包含 HTML 標籤,則它們將作為字串值的一部分包含在內,而不是被解析為 HTML。
為 text 屬性設定值會替換 <title> 的全部文字內容。
值
字串。
示例
請看下面的示例
html
<!doctype html>
<html lang="en-US">
<head>
<title>
Hello world! <span class="highlight">Isn't this wonderful</span> really?
</title>
</head>
<body></body>
</html>
js
const title = document.querySelector("title");
console.log(title.text); // "Hello world! <span class="highlight">Isn't this wonderful</span> really?"
title.text = "Update the title";
正如您所見,span 標籤未被解析;<title> 元素的內��被視為純文字,並與它們在 title 元素中出現的完全相同地返回。
規範
| 規範 |
|---|
| HTML # dom-title-text-dev |
瀏覽器相容性
載入中…