惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
C
Check Point Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
F
Full Disclosure
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
博客园 - 司徒正美
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
V
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
O
OpenAI News
Jina AI
Jina AI
PCI Perspectives
PCI Perspectives
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
I
InfoQ
D
Docker
P
Palo Alto Networks Blog
Recorded Future
Recorded Future
M
MIT News - Artificial intelligence
博客园 - Franky
B
Blog
Scott Helme
Scott Helme
博客园 - 叶小钗
D
DataBreaches.Net

博客园 - 电工男

关于电感,电抗器的Q值(品质因数) 好久不写博了. 精辟对联 Content-Disposition中filename字段的字符编码技巧[转] 转! 主键的使用 重载,继承,重写和多态的区别 webcast不更新了? - 电工男 sql server 日期类型 比较 IDENT_CURRENT、@@IDENTITY 和 SCOPE_IDENTITY 返回的标识值 SQL中判断字符串中包含字符的方法 ASP.NET生成的HTML代码 - 电工男 win7禁用休眠,献给c盘空间不足的朋友. SQLServer2005和2008的分页技术比较[转] 浏览器兼容性系列--浅谈window.attachEvent 在ASP.NET 的服务器端控件中有三种关于 ID 的属性 jQuery对&lt;img&gt;赋值 MVC JQuery 为<input>赋值 - 电工男 jquery怎么创建一个img标签 asp.net中弹出确认窗口(confirm),实现删除确认的功能 - 电工男
escape、encodeURI 、encodeURIComponent 编码与解码
电工男 · 2015-12-14 · via 博客园 - 电工男

JS escape、encodeURI 、encodeURIComponent 编码与解码

本文讨论如何对传递参数用JS编码与解码

1:编码与解码方法的对应关系

escape -----------------------------------------------------unescape

encodeURI -------------------------------------------------decodeURI

encodeURIComponent -----------------------------------encodeURIComponent

2:解码与编码方法用法

如var value1=escape('1²');  var getValue1=unescape(value1);  encodeURI ,decodeURI,encodeURIComponent ,encodeURIComponent 用法和escape,unescape用法都是一样的。

3:三种编码方法的区别和联系

编码方式:encodeURI ,encodeURIComponent 都是采用UTF-8进行对参数编码,而escape 则不是。

不会被编码的字符:encodeURI 不对:":"、"/"、";" 和 "?"字符进行编码。

用法场合:escape 不对URL进行编码,如果要对URL进行编码,应该使用encodeURI 或者encodeURIComponent ,对应的解码方法也是这样。

推荐使用的方法顺序:encodeURIComponent --encodeURI --escape 。

注意:用encodeURIComponent 、encodeURI 在前台编码后的字符串,可以直接在后台用Java解码的方式URLDecoder.decode(val,"UTF-8");进行解码,原因是这两个方法本身就是以UTF-8进行编码的。用起来很方便。