-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[zh-cn]: create docs for HTMLTitleElement (#23061)
Co-authored-by: A1lo <[email protected]>
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
title: HTMLTitleElement | ||
slug: Web/API/HTMLTitleElement | ||
l10n: | ||
sourceCommit: 32305cc3cf274fbfdcc73a296bbd400a26f38296 | ||
--- | ||
|
||
{{APIRef("HTML DOM")}} | ||
|
||
**`HTMLTitleElement`** 接口由文档的 {{HTMLElement("title")}} 实现。此元素继承 {{domxref("HTMLElement")}} 接口的所有属性和方法。 | ||
|
||
{{InheritanceDiagram}} | ||
|
||
## 实例属性 | ||
|
||
_从其父接口 {{domxref("HTMLElement")}} 继承属性。_ | ||
|
||
- {{domxref("HTMLTitleElement.text")}} | ||
- : 表示文档标题文本的字符串。 | ||
|
||
## 实例方法 | ||
|
||
_无特定方法;从其父接口 {{domxref("HTMLElement")}} 继承方法。_ | ||
|
||
## 示例 | ||
|
||
请勿混淆 `document.title` 和 `document.querySelector('title')`。 | ||
|
||
前者只是一个 setter/getter 方法,用于设置或读取文档标题的内部文本值,后者是 `HTMLTitleElement` 对象。因此你不能写:`document.title.text = "Hello world!";`。 | ||
|
||
相反,你可以简单地写:`document.title = "Hello world!";`,这相当于 `document.querySelector('title').text = "Hello world!";`。 | ||
|
||
## 规范 | ||
|
||
{{Specifications}} | ||
|
||
## 浏览器兼容性 | ||
|
||
{{Compat}} | ||
|
||
## 参见 | ||
|
||
- 实现此接口的 HTML 元素:{{HTMLElement("title")}}。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
title: HTMLTitleElement:text 属性 | ||
slug: Web/API/HTMLTitleElement/text | ||
l10n: | ||
sourceCommit: 7cc15fff0f1284ece460597b9717ca20350a1fa9 | ||
--- | ||
|
||
{{APIRef("HTML DOM")}} | ||
|
||
{{domxref("HTMLTitleElement")}} 接口的 **`text`** 属性表示文档标题的文本,仅包含文本部分;元素内的标签和其内容被剥离并忽略。 | ||
|
||
## 值 | ||
|
||
一个字符串。 | ||
|
||
## 示例 | ||
|
||
考虑一下示例: | ||
|
||
```html | ||
<!doctype html> | ||
<html lang="en-US"> | ||
<head> | ||
<title> | ||
你好世界!<span class="highlight">这难道不精彩吗</span>真的吗? | ||
</title> | ||
</head> | ||
<body></body> | ||
</html> | ||
``` | ||
|
||
```js | ||
const title = document.querySelector("title"); | ||
console.log(title.text); // 产生:“你好世界!真的吗?” | ||
``` | ||
|
||
如你所见,标签 `span` 和其内容被跳过。 | ||
|
||
## 规范 | ||
|
||
{{Specifications}} | ||
|
||
## 浏览器兼容性 | ||
|
||
{{Compat}} |