TextEncoder.prototype.encode()
method takes a
USVString
as input, and returns a
Uint8Array
containing the text given in parameters encoded with the specific method for that
TextEncoder
对象。
b1 = encoder.encode(string);
string
USVString
containing the text to encode.
A
Uint8Array
对象。
<p class="source">This is a sample paragraph.</p> <p class="result">Encoded result: </p>
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;
| 规范 | 状态 | 注释 |
|---|---|---|
|
编码
The definition of 'TextEncoder.prototype.encode()' in that specification. |
实时标准 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
encode
|
Chrome 38 | Edge 79 |
Firefox
19
|
IE 不支持 No | Opera 25 | Safari 10.1 | WebView Android 38 | Chrome Android 38 |
Firefox Android
19
|
Opera Android Yes | Safari iOS 10.3 | Samsung Internet Android 3.0 |
完整支持
不支持
实验。期望将来行为有所改变。
见实现注意事项。
TextEncoder
interface it belongs to.
TextEncoder
encode()
encodeInto()