aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/textencoder
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/textencoder
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/textencoder')
-rw-r--r--files/zh-cn/web/api/textencoder/encode/index.html74
-rw-r--r--files/zh-cn/web/api/textencoder/encoding/index.html49
-rw-r--r--files/zh-cn/web/api/textencoder/index.html150
-rw-r--r--files/zh-cn/web/api/textencoder/textencoder/index.html294
4 files changed, 567 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/textencoder/encode/index.html b/files/zh-cn/web/api/textencoder/encode/index.html
new file mode 100644
index 0000000000..96c91994bd
--- /dev/null
+++ b/files/zh-cn/web/api/textencoder/encode/index.html
@@ -0,0 +1,74 @@
+---
+title: TextEncoder.prototype.encode()
+slug: Web/API/TextEncoder/encode
+tags:
+ - 文本编码
+ - 编码
+translation_of: Web/API/TextEncoder/encode
+---
+<div>{{APIRef("Encoding API")}}</div>
+
+<p><strong><code>TextEncoder.prototype.encode()</code></strong> 方法接受一个 {{domxref("USVString")}} 作为参数,返回一个以给定的文本(字符串)参数,通过 <code>TextEncoder</code> 中指定的方法(默认 UTF-8)编码后的 {{jsxref("Global_Objects/Uint8Array", "Uint8Array")}} 类型的值。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox"><var>b1</var> = <var>encoder</var>.encode(<var>string</var>);
+</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code><var>string</var></code></dt>
+ <dd>一个包含了将要编码的文本的 {{DOMxRef("USVString")}}。</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p>一个 {{domxref("Uint8Array")}} 对象。</p>
+
+<h2 id="示例">示例</h2>
+
+<pre class="brush: html">&lt;p class="source"&gt;This is a sample paragraph.&lt;/p&gt;
+&lt;p class="result"&gt;Encoded result: &lt;/p&gt;</pre>
+
+<pre class="brush: js">const sourcePara = document.querySelector('.source');
+const resultPara = document.querySelector('.result');
+const string = sourcePara.textContent;
+
+const textEncoder = new TextEncoder();
+
+let encoded = textEncoder.encode(string);
+resultPara.textContent += encoded;</pre>
+
+<p>{{EmbedLiveSample('Examples')}}</p>
+
+<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("Encoding", "#dom-textencoder-encode", "TextEncoder.prototype.encode()")}}</td>
+ <td>{{Spec2("Encoding")}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>
+
+
+<p>{{Compat("api.TextEncoder.encode")}}</p>
+</div>
+
+<h2 id="另见">另见</h2>
+
+<ul>
+ <li>The {{DOMxRef("TextEncoder")}} interface it belongs to.</li>
+</ul>
diff --git a/files/zh-cn/web/api/textencoder/encoding/index.html b/files/zh-cn/web/api/textencoder/encoding/index.html
new file mode 100644
index 0000000000..602a16c5ff
--- /dev/null
+++ b/files/zh-cn/web/api/textencoder/encoding/index.html
@@ -0,0 +1,49 @@
+---
+title: TextEncoder.encoding
+slug: Web/API/TextEncoder/encoding
+translation_of: Web/API/TextEncoder/encoding
+---
+<p>{{APIRef("DOM")}}</p>
+
+<p>{{ SeeCompatTable }}</p>
+
+<p><strong><code>TextEncoder.encoding</code></strong> 只读属性返回一个{{domxref("DOMString")}} ,其中包含特定编码器使用的编码算法的名称。</p>
+
+<p>现在只会返回“utf-8”。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox"><em>b</em> = <em>encoder</em>.encoding;</pre>
+
+<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('Encoding', '#dom-textencoder-encoding', 'TextEncoder.encoding')}}</td>
+ <td>{{Spec2('Encoding')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器支持">浏览器支持</h2>
+
+<div>
+<div>
+
+
+<p>{{Compat("api.TextEncoder.encoding")}}</p>
+</div>
+</div>
+
+<h2 id="另见">另见</h2>
+
+<ul>
+ <li>The {{domxref("TextEncoder")}} interface it belongs to.</li>
+</ul>
diff --git a/files/zh-cn/web/api/textencoder/index.html b/files/zh-cn/web/api/textencoder/index.html
new file mode 100644
index 0000000000..223674f74b
--- /dev/null
+++ b/files/zh-cn/web/api/textencoder/index.html
@@ -0,0 +1,150 @@
+---
+title: TextEncoder
+slug: Web/API/TextEncoder
+tags:
+ - API
+ - 参考
+ - 接口
+ - 编码
+translation_of: Web/API/TextEncoder
+---
+<div>{{APIRef("Encoding API")}}</div>
+
+<p><code><strong>TextEncoder</strong></code> 接受代码点流作为输入,并提供 UTF-8 字节流作为输出。</p>
+
+<div class="blockIndicator note">
+<p><strong>Note</strong>: There is a polyfill implementation to support non-UTF-8 text encodings on <a href="https://github.com/inexorabletash/text-encoding">GitHub</a>.</p>
+</div>
+
+<h2 id="例子">例子</h2>
+
+<pre class="brush: js; notranslate">const encoder = new TextEncoder()
+const view = encoder.encode('€')
+console.log(view); // Uint8Array(3) [226, 130, 172]
+</pre>
+
+<h2 id="构造器">构造器</h2>
+
+<dl>
+ <dt>{{domxref("TextEncoder.TextEncoder", "TextEncoder()")}}</dt>
+ <dd>返回一个新构造的 <code>TextEncoder</code>,它默认使用 UTF-8 编码将代码点流转换成字节流。</dd>
+</dl>
+
+<h2 id="属性">属性</h2>
+
+<p><em><code>TextEncoder</code> 接口不继承任何属性。</em></p>
+
+<dl>
+ <dt>{{domxref("TextEncoder.encoding")}} {{readonlyInline}}</dt>
+ <dd>总是返回 "<code>utf-8</code>"。</dd>
+</dl>
+
+<h2 id="方法">方法</h2>
+
+<p><em><code>TextEncoder</code> 接口不继承任何方法。</em></p>
+
+<dl>
+ <dt>{{domxref("TextEncoder.encode()")}}</dt>
+ <dd>接受一个 {{domxref("USVString")}} 作为输入,返回一个包含文本的 {{jsxref("Uint8Array")}},其中的文本使用 UTF-8 编码。</dd>
+ <dt>{{DOMxRef("TextEncoder.prototype.encodeInto()")}}</dt>
+ <dd>接受一个 {{domxref("USVString")}} 作为输入、一个{{jsxref("Uint8Array")}} 作为输出目标,返回一个指示编码进度的目录(dictionary)对象。此方法的性能可能回比更早出现的 <code>encode()</code> 方法好一些。</dd>
+</dl>
+
+<h2 id="Polyfill">Polyfill</h2>
+
+<p>The below polyfill is compliant with the standard and therefore only supports UTF-8. It is designed to work in IE5 "out of the box". However, in IE5-IE9, it will return a regular Array instead of a TypedArray. In those cases a polyfill might be impractical for large strings. Finally, note that you should run the below code through a minifier (especially closure compiler) to turn sequences like <code>0x1e &lt;&lt; 3</code> into <code>0xf0</code>. These sequences are not already precomputed because they serve to aesthetically illustrate how the polyfill works.</p>
+
+<pre class="brush: js notranslate">if (typeof TextEncoder === "undefined") {
+ TextEncoder=function TextEncoder(){};
+ TextEncoder.prototype.encode = function encode(str) {
+ "use strict";
+ var Len = str.length, resPos = -1;
+ // The Uint8Array's length must be at least 3x the length of the string because an invalid UTF-16
+ // takes up the equivelent space of 3 UTF-8 characters to encode it properly. However, Array's
+ // have an auto expanding length and 1.5x should be just the right balance for most uses.
+ var resArr = typeof Uint8Array === "undefined" ? new Array(Len * 1.5) : new Uint8Array(Len * 3);
+ for (var point=0, nextcode=0, i = 0; i !== Len; ) {
+ point = str.charCodeAt(i), i += 1;
+ if (point &gt;= 0xD800 &amp;&amp; point &lt;= 0xDBFF) {
+ if (i === Len) {
+ resArr[resPos += 1] = 0xef/*0b11101111*/; resArr[resPos += 1] = 0xbf/*0b10111111*/;
+ resArr[resPos += 1] = 0xbd/*0b10111101*/; break;
+ }
+ // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
+ nextcode = str.charCodeAt(i);
+ if (nextcode &gt;= 0xDC00 &amp;&amp; nextcode &lt;= 0xDFFF) {
+ point = (point - 0xD800) * 0x400 + nextcode - 0xDC00 + 0x10000;
+ i += 1;
+ if (point &gt; 0xffff) {
+ resArr[resPos += 1] = (0x1e/*0b11110*/&lt;&lt;3) | (point&gt;&gt;&gt;18);
+ resArr[resPos += 1] = (0x2/*0b10*/&lt;&lt;6) | ((point&gt;&gt;&gt;12)&amp;0x3f/*0b00111111*/);
+ resArr[resPos += 1] = (0x2/*0b10*/&lt;&lt;6) | ((point&gt;&gt;&gt;6)&amp;0x3f/*0b00111111*/);
+ resArr[resPos += 1] = (0x2/*0b10*/&lt;&lt;6) | (point&amp;0x3f/*0b00111111*/);
+ continue;
+ }
+ } else {
+ resArr[resPos += 1] = 0xef/*0b11101111*/; resArr[resPos += 1] = 0xbf/*0b10111111*/;
+ resArr[resPos += 1] = 0xbd/*0b10111101*/; continue;
+ }
+ }
+ if (point &lt;= 0x007f) {
+ resArr[resPos += 1] = (0x0/*0b0*/&lt;&lt;7) | point;
+ } else if (point &lt;= 0x07ff) {
+ resArr[resPos += 1] = (0x6/*0b110*/&lt;&lt;5) | (point&gt;&gt;&gt;6);
+ resArr[resPos += 1] = (0x2/*0b10*/&lt;&lt;6) | (point&amp;0x3f/*0b00111111*/);
+ } else {
+ resArr[resPos += 1] = (0xe/*0b1110*/&lt;&lt;4) | (point&gt;&gt;&gt;12);
+ resArr[resPos += 1] = (0x2/*0b10*/&lt;&lt;6) | ((point&gt;&gt;&gt;6)&amp;0x3f/*0b00111111*/);
+ resArr[resPos += 1] = (0x2/*0b10*/&lt;&lt;6) | (point&amp;0x3f/*0b00111111*/);
+ }
+ }
+ if (typeof Uint8Array !== "undefined") return resArr.subarray(0, resPos + 1);
+ // else // IE 6-9
+ resArr.length = resPos + 1; // trim off extra weight
+ return resArr;
+ };
+ TextEncoder.prototype.toString = function(){return "[object TextEncoder]"};
+ try { // Object.defineProperty only works on DOM prototypes in IE8
+ Object.defineProperty(TextEncoder.prototype,"encoding",{
+ get:function(){if(TextEncoder.prototype.isPrototypeOf(this)) return"utf-8";
+ else throw TypeError("Illegal invocation");}
+ });
+ } catch(e) { /*IE6-8 fallback*/ TextEncoder.prototype.encoding = "utf-8"; }
+ if(typeof Symbol!=="undefined")TextEncoder.prototype[Symbol.toStringTag]="TextEncoder";
+}
+</pre>
+
+<p><small>Source: <a href="https://github.com/anonyco/FastestSmallestTextEncoderDecoder" rel="noopener">https://github.com/anonyco/FastestSmallestTextEncoderDecoder</a></small></p>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">备注</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Encoding', '#interface-textencoder', 'TextEncoder')}}</td>
+ <td>{{Spec2('Encoding')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("api.TextEncoder")}}</p>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li>The {{DOMxRef("TextDecoder")}} interface describing the inverse operation.</li>
+ <li><a href="/en-US/Add-ons/Code_snippets/StringView" title="/en-US/docs/Web/JavaScript/Typed_arrays/StringView"><code>StringView</code></a> – a C-like representation of strings based on typed arrays</li>
+ <li>A <a href="https://github.com/inexorabletash/text-encoding" title="http://code.google.com/p/stringencoding/">shim</a> allowing to use this interface in browsers that don't support it.</li>
+ <li><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.importGlobalProperties">Components.utils.importGlobalProperties</a></code></li>
+ <li><a href="https://nodejs.org/api/util.html#util_class_util_textencoder">Node.js supports global export from v11.0.0</a></li>
+</ul>
diff --git a/files/zh-cn/web/api/textencoder/textencoder/index.html b/files/zh-cn/web/api/textencoder/textencoder/index.html
new file mode 100644
index 0000000000..ce65b791c4
--- /dev/null
+++ b/files/zh-cn/web/api/textencoder/textencoder/index.html
@@ -0,0 +1,294 @@
+---
+title: TextEncoder()
+slug: Web/API/TextEncoder/TextEncoder
+tags:
+ - TextEncoder
+ - 接口
+ - 编码
+ - 编码器
+translation_of: Web/API/TextEncoder/TextEncoder
+---
+<p>{{apiref("TextEncoder")}}{{seeCompatTable}}</p>
+
+<p>The <code><strong>TextEncoder()</strong></code> 构造函数返回一个新创建的{{domxref("TextEncoder")}}对象。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox"><em>encoder</em> = new TextEncoder();
+</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt>
+ <ul>
+ <li>TextEncoder() 从 Firefox 48 and Chrome 53 开始不再需要参数</li>
+ </ul>
+
+ <p><strong>Note</strong>: 在Firefox 48和Chrome 53之前,编码类型标签被接受为TextEncoder对象的参数,现在这两个浏览器已经删除了除utf-8之外的任何编码器类型的支持,以符合规范。 传入TextEncoder构造函数的任何类型标签现在都将被忽略,并且将创建一个utf-8 TextEncoder。</p>
+ </dt>
+</dl>
+
+<ul>
+ <li>旧的参数:</li>
+</ul>
+
+<dl>
+ <dd>
+ <table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Possible values of <em>utfLabel</em></th>
+ <th scope="col">Encoding</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>"<code title="">unicode-1-1-utf-8</code>", "<code title="">utf-8</code>", "<code>utf8</code>"</td>
+ <td><code>'utf-8'</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">866</code>", "<code title="">cp866</code>", "<code title="">csibm866</code>", "<code title="">ibm866</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Code_page_866', "'ibm866'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">csisolatin2</code>", "<code title="">iso-8859-2</code>", "<code title="">iso-ir-101</code>", "<code title="">iso8859-2</code>", "<code title="">iso88592</code>", "<code title="">iso_8859-2</code>", "<code title="">iso_8859-2:1987</code>", "<code title="">l2</code>", "<code title="">latin2</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'ISO/IEC_8859-2', "'iso-8859-2'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">csisolatin3</code>", "<code title="">iso-8859-3</code>", "<code title="">iso-ir-109</code>", "<code title="">iso8859-3</code>", "<code title="">iso88593</code>", "<code title="">iso_8859-3</code>", "<code title="">iso_8859-3:1988</code>", "<code title="">l3</code>", "<code title="">latin3</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'ISO/IEC_8859-3', "'iso-8859-3'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">csisolatin4</code>", "<code title="">iso-8859-4</code>", "<code title="">iso-ir-110</code>", "<code title="">iso8859-4</code>", "<code title="">iso88594</code>", "<code title="">iso_8859-4</code>", "<code title="">iso_8859-4:1988</code>", "<code title="">l4</code>", "<code title="">latin4</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'ISO/IEC_8859-4', "'iso-8859-4'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">csisolatincyrillic</code>", "<code title="">cyrillic</code>", "<code title="">iso-8859-5</code>", "<code title="">iso-ir-144</code>", "<code title="">iso88595</code>", "<code title="">iso_8859-5</code>", "<code title="">iso_8859-5:1988</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'ISO/IEC_8859-5', "'iso-8859-5'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">arabic</code>", "<code title="">asmo-708</code>", "<code title="">csiso88596e</code>", "<code title="">csiso88596i</code>", "<code title="">csisolatinarabic</code>", "<code title="">ecma-114</code>", "<code title="">iso-8859-6</code>", "<code title="">iso-8859-6-e</code>", "<code title="">iso-8859-6-i</code>", "<code title="">iso-ir-127</code>", "<code title="">iso8859-6</code>", "<code title="">iso88596</code>", "<code title="">iso_8859-6</code>", "<code title="">iso_8859-6:1987</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'ISO/IEC_8859-6', "'iso-8859-6'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">csisolatingreek</code>", "<code title="">ecma-118</code>", "<code title="">elot_928</code>", "<code title="">greek</code>", "<code title="">greek8</code>", "<code title="">iso-8859-7</code>", "<code title="">iso-ir-126</code>", "<code title="">iso8859-7</code>", "<code title="">iso88597</code>", "<code title="">iso_8859-7</code>", "<code title="">iso_8859-7:1987</code>", "<code title="">sun_eu_greek</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'ISO/IEC_8859-7', "'iso-8859-7'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">csiso88598e</code>", "<code title="">csisolatinhebrew</code>", "<code title="">hebrew</code>", "<code title="">iso-8859-8</code>", "<code title="">iso-8859-8-e</code>", "<code title="">iso-ir-138</code>", "<code title="">iso8859-8</code>", "<code title="">iso88598</code>", "<code title="">iso_8859-8</code>", "<code title="">iso_8859-8:1988</code>", "<code title="">visual</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'ISO/IEC_8859-8', "'iso-8859-8'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">csiso88598i</code>", "<code title="">iso-8859-8-i</code>", "<code title="">logical</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'ISO-8859-8-I', "'iso-8859-8i'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">csisolatin6</code>", "<code title="">iso-8859-10</code>", "<code title="">iso-ir-157</code>", "<code title="">iso8859-10</code>", "<code title="">iso885910</code>", "<code title="">l6</code>", "<code title="">latin6</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'ISO/IEC_8859-10', "'iso-8859-10'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">iso-8859-13</code>", "<code title="">iso8859-13</code>", "<code title="">iso885913</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'ISO/IEC_8859-13', "'iso-8859-13'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">iso-8859-14</code>", "<code title="">iso8859-14</code>", "<code title="">iso885914</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'ISO/IEC_8859-14', "'iso-8859-14'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">csisolatin9</code>", "<code title="">iso-8859-15</code>", "<code title="">iso8859-15</code>", "<code title="">iso885915</code>", "<code title="">l9</code>", "<code title="">latin9</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'ISO/IEC_8859-15', "'iso-8859-15'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">iso-8859-16</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'ISO/IEC_8859-16', "'iso-8859-16'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">cskoi8r</code>", "<code title="">koi</code>", "<code title="">koi8</code>", "<code title="">koi8-r</code>", "<code title="">koi8_r</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'KOI8-R', "'koi8-r'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">koi8-u</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'KOI8-U', "'koi8-u'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">csmacintosh</code>", "<code title="">mac</code>", "<code title="">macintosh</code>", "<code title="">x-mac-roman</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Mac OS Roman', "'macintosh'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">dos-874</code>", "<code title="">iso-8859-11</code>", "<code title="">iso8859-11</code>", "<code title="">iso885911</code>", "<code title="">tis-620</code>", "<code title="">windows-874</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Windows-874', "'windows-874'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">cp1250</code>", "<code title="">windows-1250</code>", "<code title="">x-cp1250</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Windows-1250', "'windows-1250'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">cp1251</code>", "<code title="">windows-1251</code>", "<code title="">x-cp1251</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Windows-1251', "'windows-1251'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">ansi_x3.4-1968</code>", "<code title="">ascii</code>", "<code title="">cp1252</code>", "<code title="">cp819</code>", "<code title="">csisolatin1</code>", "<code title="">ibm819</code>", "<code title="">iso-8859-1</code>", "<code title="">iso-ir-100</code>", "<code title="">iso8859-1</code>", "<code title="">iso88591</code>", "<code title="">iso_8859-1</code>", "<code title="">iso_8859-1:1987</code>", "<code title="">l1</code>", "<code title="">latin1</code>", "<code title="">us-ascii</code>", "<code title="">windows-1252</code>", "<code title="">x-cp1252</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Windows-1252', "'windows-1252'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">cp1253</code>", "<code title="">windows-1253</code>", "<code title="">x-cp1253</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Windows-1253', "'windows-1253'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">cp1254</code>", "<code title="">csisolatin5</code>", "<code title="">iso-8859-9</code>", "<code title="">iso-ir-148</code>", "<code title="">iso8859-9</code>", "<code title="">iso88599</code>", "<code title="">iso_8859-9</code>", "<code title="">iso_8859-9:1989</code>", "<code title="">l5</code>", "<code title="">latin5</code>", "<code title="">windows-1254</code>", "<code title="">x-cp1254</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Windows-1254', "'windows-1254'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">cp1255</code>", "<code title="">windows-1255</code>", "<code title="">x-cp1255</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Windows-1255', "'windows-1255'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">cp1256</code>", "<code title="">windows-1256</code>", "<code title="">x-cp1256</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Windows-1256', "'windows-1256'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">cp1257</code>", "<code title="">windows-1257</code>", "<code title="">x-cp1257</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Windows-1257', "'windows-1257'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">cp1258</code>", "<code title="">windows-1258</code>", "<code title="">x-cp1258</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Windows-1258', "'windows-1258'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">x-mac-cyrillic</code>", "<code title="">x-mac-ukrainian</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Macintosh Cyrillic encoding', "'x-mac-cyrillic'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">chinese</code>", "<code title="">csgb2312</code>", "<code title="">csiso58gb231280</code>", "<code title="">gb2312</code>", "<code title="">gb_2312</code>", "<code title="">gb_2312-80</code>", "<code title="">gbk</code>", "<code title="">iso-ir-58</code>", "<code title="">x-gbk</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'GBK', "'gbk'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">gb18030</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'GB_18030', "'gb18030'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">hz-gb-2312</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'HZ_(character_encoding)', "'hz-gb-2312'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">big5</code>", "<code title="">big5-hkscs</code>", "<code title="">cn-big5</code>", "<code title="">csbig5</code>", "<code title="">x-x-big5</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Big5', "'big5'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">cseucpkdfmtjapanese</code>", "<code title="">euc-jp</code>", "<code title="">x-euc-jp</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Extended_Unix_Code#EUC-JP', "'euc-jp'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">csiso2022jp</code>", "<code title="">iso-2022-jp</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'ISO/IEC_2022#ISO-2022-JP', "'iso-2022-jp'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">csshiftjis</code>", "<code title="">ms_kanji</code>", "<code title="">shift-jis</code>", "<code title="">shift_jis</code>", "<code title="">sjis</code>", "<code title="">windows-31j</code>", "<code title="">x-sjis</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Shift JIS', "'shift-jis'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">cseuckr</code>", "<code title="">csksc56011987</code>", "<code title="">euc-kr</code>", "<code title="">iso-ir-149</code>", "<code title="">korean</code>", "<code title="">ks_c_5601-1987</code>", "<code title="">ks_c_5601-1989</code>", "<code title="">ksc5601</code>", "<code title="">ksc_5601</code>", "<code title="">windows-949</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'Extended_Unix_Code#EUC-KR', "'euc-kr'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">csiso2022kr</code>", "<code title="">iso-2022-kr</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'ISO/IEC_2022#ISO-2022-KR', "'iso-2022-kr'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">utf-16be</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'UTF-16#Byte_order_encoding_schemes', "'utf-16be'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">utf-16</code>", "<code title="">utf-16le</code>"</td>
+ <td><code>{{interwiki('wikipedia', 'UTF-16#Byte_order_encoding_schemes', "'utf-16le'")}}</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">x-user-defined</code>"</td>
+ <td><code>'x-user-defined'</code></td>
+ </tr>
+ <tr>
+ <td>"<code title="">iso-2022-cn</code>", "<code title="">iso-2022-cn-ext</code>"</td>
+ <td><code>'replacement'</code></td>
+ </tr>
+ </tbody>
+ </table>
+ </dd>
+</dl>
+
+<h2 id="例子">例子</h2>
+
+<pre class="brush: js"><code class="language-js">var textEncoder <span class="operator token">=</span> new TextEncoder<span class="function token"><span class="punctuation token">("iso-8859-1"</span></span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre>
+
+<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('Encoding', '#dom-textencoder', 'TextEncode()')}}</td>
+ <td>{{Spec2('Encoding')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器支持">浏览器支持</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<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 (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoDesktop("19.0")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}</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 Phone</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoMobile("19.0")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="另见">另见</h2>
+
+<ul>
+ <li>The {{domxref("TextEncoder")}} interface it belongs to。</li>
+</ul>