1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
---
title: Text
slug: Web/API/Text
translation_of: Web/API/Text
---
<p>{{ ApiRef() }}</p>
<p>The <strong><code>Text</code></strong> interface represents the textual content of {{domxref("Element")}} or {{domxref("Attr")}}. If an element has no markup within its content, it has a single child implementing <code>Text</code> that contains the element's text. However, if the element contains markup, it is parsed into information items and <code>Text</code> nodes that form its children.</p>
<p>New documents have a single <code>Text</code> node for each block of text. Over time, more <code>Text</code> nodes may be created as the document's content changes. The {{domxref("Node.normalize()")}} method merges adjacent <code>Text</code> objects back into a single node for each block of text.</p>
<h2 id="Properties" name="Properties">属性</h2>
<dl>
<dt>
{{domxref("Text.isElementContentWhitespace")}} {{readonlyInline}}{{ obsolete_inline() }}</dt>
<dd>
<p>Returns a {{domxref("Boolean")}} flag indicatingwhether or not the text node contains only whitespace.</p>
</dd>
<dt>
{{domxref("Text.wholeText")}} {{readonlyInline}}</dt>
<dd>
Returns a {{domxref("DOMString")}} containing the text of all <code>Text</code> nodes logically adjacent to this {{domxref("Node")}}, concatenated in document order.</dd>
</dl>
<h2 id="Methods" name="Methods">构造函数</h2>
<dl>
<dt>
{{domxref("Text.Text", "Text()")}} {{experimental_inline}}</dt>
<dd>
Returns a <code>Text</code> node with the parameter as its textual content.</dd>
</dl>
<h2 id="Methods" name="Methods">方法</h2>
<dl>
<dt>
{{domxref("Text.replaceWholeText")}} {{ obsolete_inline() }}</dt>
<dd>
Replaces the text of the current node and all logically adjacent nodes with the specified text.</dd>
</dl>
<dl>
<dt>
<span class="internal">{{domxref("Text.splitText")}}</span></dt>
<dd>
Breaks the node into two nodes at a specified offset.</dd>
</dl>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('DOM WHATWG', '#text', 'Text')}}</td>
<td>{{Spec2('DOM WHATWG')}}</td>
<td>Removed the <code>isElementContentWhitespace</code> property.<br>
Removed the <code>replaceWholeText()</code> method.<br>
Added the <code>Text()</code> constructor.</td>
</tr>
<tr>
<td>{{SpecName('DOM3 Core', 'core.html#ID-1312295772', 'Text')}}</td>
<td>{{Spec2('DOM3 Core')}}</td>
<td>Added the <code>isElementContentWhitespace</code> and <code>wholeText</code> properties.<br>
Added the <code>replaceWholeText()</code> method.</td>
</tr>
<tr>
<td>{{SpecName('DOM2 Core', 'core.html#ID-1312295772', 'Text')}}</td>
<td>{{Spec2('DOM2 Core')}}</td>
<td>No change from {{SpecName('DOM1')}}.</td>
</tr>
<tr>
<td>{{SpecName('DOM1', 'level-one-core.html#ID-1312295772', 'Text')}}</td>
<td>{{Spec2('DOM1')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
{{Compat("api.Text")}}
<h2 id="相关链接">相关链接</h2>
<ul>
<li><a href="/en-US/docs/DOM/DOM_Reference" title="/en-US/docs/DOM/DOM_Reference">The DOM interfaces index</a>.</li>
</ul>
|