Difference between escape(), encodeURI(), encodeURIComponent()
Difference between escape(), encodeURI(), encodeURIComponent()
回答1
For the visually minded, here's a table showing the effects of encodeURI()
, encodeURIComponent()
and escape()
on the commonly-used symbolic ASCII characters:
Char encUrI encURIComp escape
* * * *
. . . .
_ _ _ _
- - - -
~ ~ ~ %7E
' ' ' %27
! ! ! %21
( ( ( %28
) ) ) %29
/ / %2F /
+ + %2B +
@ @ %40 @
? ? %3F %3F
= = %3D %3D
: : %3A %3A
# # %23 %23
; ; %3B %3B
, , %2C %2C
$ $ %24 %24
& & %26 %26
%20 %20 %20
% %25 %25 %25
^ %5E %5E %5E
[ %5B %5B %5B
] %5D %5D %5D
{ %7B %7B %7B
} %7D %7D %7D
< %3C %3C %3C
> %3E %3E %3E
" %22 %22 %22
\ %5C %5C %5C
| %7C %7C %7C
` %60 %60 %60
Another vital difference is that unescape()
does not handle multi-byte UTF-8 sequences whereas decodeURI[Component]()
does:
decodeURIComponent("%C3%A9") == "é"
unescape("%C3%A9") == "é"
回答2
escape
— broken, deprecated, do not useencodeURI
— encodes characters that are not allowed (raw) in URLs (use it to fix up broken URIs if you can't fix them beforehand)encodeURIComponent
— asencodeURI
plus characters with special meaning in URIs (use it to encode data for inserting into a URI)
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2019-09-02 How to Publish a NuGet Package
2015-09-02 Three ways to do WCF instance management
2015-09-02 WCF Concurrency (Single, Multiple, and Reentrant) and Throttling