← 返回工具箱
🔐 Escape加密/解密

📖 知识

三种编码方法对比

方法不编码的字符编码格式适用场景
escape() A-Z a-z 0-9 @*_+-./ %xx 或 %uxxxx 已废弃,仅用于旧代码兼容
encodeURI() A-Z a-z 0-9 ;,/?:@&=+$-_.!~*'()# %xx (UTF-8) 编码完整URI,保留URI结构字符
encodeURIComponent() A-Z a-z 0-9 -_.!~*'() %xx (UTF-8) 编码URI参数值,编码所有特殊字符

编码示例对比

原文escapeencodeURIencodeURIComponent
hello world hello%20world hello%20world hello%20world
a=1&b=2 a%3D1%26b%3D2 a=1&b=2 a%3D1%26b%3D2
https://x.com https%3A//x.com https://x.com https%3A%2F%2Fx.com
你好 %u4F60%u597D %E4%BD%A0%E5%A5%BD %E4%BD%A0%E5%A5%BD

保留字符说明

URI中的保留字符包括: ; , / ? : @ & = + $ #

encodeURI() 不会编码这些保留字符,因为它们在完整URI中有特殊含义。

encodeURIComponent() 会编码这些保留字符,因此适合编码查询参数的值。

使用建议