博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
encodeURI与decodeURI
阅读量:4674 次
发布时间:2019-06-09

本文共 973 字,大约阅读时间需要 3 分钟。

Global对象的ecodeURI方法可以对URI进行编码,与其类似的还有一个方法encodeURIComponent方法。

相应的对URI的解码方法也有两个:decodeURI、decodeURIComponent, 下面将对这四个方法的用法做个简要介绍。

 

encodeURI只对URI中的空格进行编码,所以decodeURI()方法主要用于对整个URI进行编码。

encodeURIComponent会对URI中的所有非标准字符进行编码。

所以decodeURIComponent()方法主要用于对URI中的某一段进行编码。比如对跟在URI后面的查询字符串的参数进行编码。

举例说明:

var uri = "http://www.cnblogs.com/lidgblogs/p/test 7124770.html";console.log(encodeURI(uri)); // http://www.cnblogs.com/lidgblogs/p/test%207124770.htmlconsole.log(encodeURIComponent(uri)); // http%3A%2F%2Fwww.cnblogs.com%2Flidgblogs%2Fp%2Ftest%207124770.html

 

decodeURI: 只能对使用encodeURI编码的字符进行解码。

decodeURIComponent: 只能对使用encodeURIComponent编码的字符进行解码。

举例说明:

var uri = "http%3A%2F%2Fwww.cnblogs.com%2Flidgblogs%2Fp%2Ftest%207124770.html";console.log(decodeURI(uri)); // http%3A%2F%2Fwww.cnblogs.com%2Flidgblogs%2Fp%2Ftest 7124770.htmlconsole.log(decodeURIComponent(uri)); // http://www.cnblogs.com/lidgblogs/p/test 7124770.html

 

转载于:https://www.cnblogs.com/lidgblogs/p/7124770.html

你可能感兴趣的文章
决策树
查看>>
团队作业
查看>>
如何避免在简单业务逻辑上面的细节上面出错
查看>>
win7,Ubuntu 12.04 双系统修改启动项顺序三方法
查看>>
python--列表推导式和生成表达式
查看>>
P - Psychos in a Line 单调队列
查看>>
POJ 2653 Pick-up sticks(计算几何)
查看>>
大型网站高并发的架构演变图-摘自网络
查看>>
8丶运行及总结
查看>>
Unity获取手机的电量时间
查看>>
Spring框架:Spring容器具体解释
查看>>
MongoDB 3.2 从安装到使用。
查看>>
XCODE快捷键和功能汇总篇(不断更新)
查看>>
Servlet开发(一)
查看>>
linux下如何查看某个容器的详细信息?
查看>>
bzoj 2843: 极地旅行社
查看>>
车林通购车之家--购车计算器模块--算法js
查看>>
webpack使用教程
查看>>
MySQL学习8 - 数据的增删改
查看>>
Linux笔记(开机自动将kerne log保存到SD卡中)
查看>>