Encoding modes
编码模式
- encodeURIComponent — escapes everything except
A–Z a–z 0–9 - _ . ! ~ * ' ( ). Use for query parameter values and path segments.—— 转义除A–Z a–z 0–9 - _ . ! ~ * ' ( )之外的所有字符。用于查询参数值与路径段。 - encodeURI — preserves URL syntax characters like
/ : ? # & = + $ , ;. Use for full URLs where you want the structure intact.—— 保留 URL 结构字符/ : ? # & = + $ , ;。用于需要保留 URL 结构的完整链接。 - decodeURIComponent — reverses percent-encoding on a string. Throws on malformed sequences such as
%ZZ.—— 反向百分号编码。遇到%ZZ等非法序列会抛出错误。
Read the URL encoding deep dive for examples and pitfalls.
阅读 URL 编码深入解析 查看示例与常见坑。