Text
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Text
接口表示 DOM 树中的一个文本节点。
要理解什么是文本节点,请看下面的文档:
html
<html lang="en" class="e">
<head>
<title>Aliens?</title>
</head>
<body>
Why yes.
</body>
</html>
在这个文档中,有 5 个文本节点,其内容如下:
"\n "
(在<head>
开始标签之后,一个换行符后跟四个空格)"Aliens?"
(title
元素的内容)"\n "
(在</head>
结束标签之后,一个换行符后跟两个空格)"\n "
(在<body>
开始标签之后,一个换行符后跟两个空格)"\n Why yes.\n \n\n"
(body
元素的内容)
每个文本节点都是一个对象,具有本文中描述的属性和方法。
构造函数
Text()
-
返回一个新的
Text
节点,将参数作为其文本内容。
实例属性
从其父类 CharacterData
、Node
和 EventTarget
继承属性。
Text.assignedSlot
只读-
返回一个
HTMLSlotElement
,表示当前节点所在的<slot>
。 Text.wholeText
只读-
返回一个由与当前节点相邻的所有文本(
Text
)节点的文本内容按文档顺序拼接成一个字符串。
实例方法
从其父类 CharacterData
、Node
和 EventTarget
继承方法。
Text.splitText
-
在指定的偏移位置将节点分成两个节点。
规范
Specification |
---|
DOM # interface-text |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Text | ||||||||||||
Text() constructor | ||||||||||||
assignedSlot | ||||||||||||
getBoxQuads | ||||||||||||
splitText | ||||||||||||
wholeText |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
- See implementation notes.
- User must explicitly enable this feature.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.