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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
---
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>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Basic support</td>
<td>1.0 [3]</td>
<td>{{CompatGeckoDesktop("1.0")}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}} [3]</td>
<td>{{CompatVersionUnknown}} [4]</td>
</tr>
<tr>
<td><code>wholeText</code></td>
<td>1.0</td>
<td>{{CompatGeckoDesktop("1.9.1")}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
<tr>
<td><code>isElementContentWhitespace</code></td>
<td>{{CompatNo}}</td>
<td>{{CompatVersionUnknown}}<br>
Removed in {{CompatGeckoDesktop("10")}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td><code>replaceWholeText</code></td>
<td>{{CompatVersionUnknown}} [1] [2]</td>
<td>{{CompatGeckoDesktop("1.9.1")}}<br>
Removed in {{CompatGeckoDesktop("10")}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}} [1] [2]</td>
<td>{{CompatVersionUnknown}} [4]</td>
</tr>
<tr>
<td><code>Text()</code> constructor</td>
<td>28.0</td>
<td>{{CompatGeckoDesktop("24.0")}}</td>
<td>{{CompatNo}}</td>
<td>15.0</td>
<td>{{CompatNo}}</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{CompatVersionUnknown}} [3]</td>
<td>{{CompatGeckoMobile("1.0")}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}} [3]</td>
<td>{{CompatVersionUnknown}} [4]</td>
</tr>
<tr>
<td><code>wholeText</code></td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoMobile("1.9.1")}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
<tr>
<td><code>isElementContentWhitespace</code></td>
<td>{{CompatNo}}</td>
<td>{{CompatVersionUnknown}}<br>
Removed in {{CompatGeckoMobile("10")}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td><code>replaceWholeText</code></td>
<td>{{CompatVersionUnknown}} [1] [2]</td>
<td>{{CompatGeckoMobile("1.9.1")}}<br>
Removed in {{CompatGeckoMobile("10")}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}} [1] [2]</td>
<td>{{CompatVersionUnknown}} [4]</td>
</tr>
<tr>
<td><code>Text()</code> constructor</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoMobile("24.0")}}</td>
<td>{{CompatNo}}</td>
<td>15.0</td>
<td>{{CompatNo}}</td>
</tr>
</tbody>
</table>
</div>
<p>[1] Chromium is currently considering dropping its support.</p>
<p>[2] Before Chrome 30 and Opera 17, the argument wasn't mandatory, like required by the specification.</p>
<p>[3] Before Chrome 30 and Opera 17, <code>splitText()</code> argument was not mandatory, as required by the specification and implemented by IE and Gecko-based browsers.</p>
<p>[4] The argument is not mandatory, though required by the spec.</p>
<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>
|