You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
changed the title [-][js] 第121天 请说说escape、encodeURI、urlencodeComponent和urlencode的区别?[/-][+][js] 第121天 请说说escape、encodeURI、decodeURI、encodeURIComponent和decodeURIComponent的区别?[/+]on Aug 15, 2019
Activity
93xiaoli commentedon Aug 14, 2019
之前完全不知道 查了才知道的
用来编码string,现在不推荐使用,注意无法处理特殊字符* @ - _ + . /
用来编译URI,无法编码A-Z a-z 0-9 ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #,因为没法编译"&", "+", "=",无法完成get和post指令,但encodeURIComponent可以编译
无法编码 A-Z a-z 0-9 - _ . ! ~ * ' ( )
我没有查到urlencodeComponent和urlencode,等看着大神的解答。谢谢@DarthVaderrr指正
xxf1996 commentedon Aug 15, 2019
@haizhilin2013 我也没查到
urlencodeComponent
和urlencode
这两个方法;是不是encodeURIComponent
和encodeURI
?[-][js] 第121天 请说说escape、encodeURI、urlencodeComponent和urlencode的区别?[/-][+][js] 第121天 请说说escape、encodeURI、decodeURI、encodeURIComponent和decodeURIComponent的区别?[/+]haizhilin2013 commentedon Aug 15, 2019
@93xiaoli @xxf1996 多谢提醒,我写错了!下次我会注意,多验证下!
ghost commentedon Aug 15, 2019
题目与#574 基本类似。
另外,
escape()
将会把字符串中除了字母、数字以及一部分符号以外的所有转义为%XX
格式的转义序列,可以通过unescape()
转回。它们是已经被弃用的方法,不建议使用。对于之前的错误题目:
urlencode
大概指的是 MIMEapplication/x-www-form-urlencoded
,它将键值对信息序列化为key1=value1&key2=value2&...
的形式,并且可以连接在 url 后面。haizhilin2013 commentedon Aug 15, 2019
@t532 好的,收到!
DarthVaderrr commentedon Aug 16, 2019
上面有小伙伴提到加密,需要注意的是这些都是编码方法,不是加密方法,前端无法对数据进行加密,只能编码,也就是说,任何懂前端技术的人都可以无障碍地获得数据原来的信息,因为这些编码都是可逆的,编码规则是恒定的
nowherebutup commentedon Oct 17, 2019
escape是之前的转义解码的函数,
encodeURI的范围比encodeURIComponent要小,
zhaofeipeter commentedon Jul 30, 2020
1、如果只是编码字符串,不和URL有半毛钱关系,那么用escape,而且这个方法一般不会用到。
2、如果你需要编码整个URL,然后需要使用这个URL,那么用encodeURI。
3、当你需要编码URL中的参数的时候,那么encodeURIComponent是最好方法。
xiaoqiangz commentedon Jul 7, 2022
escape 用来编码字符串的,不过已经在web标准中被删除了,如果要用尽量使用encodeUrl,如果要编码url要使用 encodeUrl, 如果有分隔符或其他特殊字符就要使用encodeURIComponent,但是该方法不会对 ASCII 字母和数字进行编码,也不会对这些 ASCII 标点符号进行编码。