JavaScript decodeURI()与decodeURIComponent() 使用与区别
decodeURI()定义和用法:decodeURI()函数可对encodeURI()函数编码过的URI进行解码.
语法:decodeURI(URIstring)
参数描述:URIstring必需,一个字符串,含有要解码的URI组或其他要解码的文本.
返回值:URIstring的副本,其中的十六进制转义序列将被它们表示的字符替换.
decodeURIComponent()定义和用法:decodeURIComponent()函数可对encodeURIComponent()函数编码过的URI进行解码.
语法:decodeURIComponent(URIstring)
参数描述:URIstring必需,一个字符串,含有解码的URI组件或其他要解码的文本.
返回值:URIstring的副本,其中的十六进制转义序列将被它们表示的字符替换.
以上是对于用法的说明,但是在实际的使用过程中有一下问题:
#特殊符号进行进行编码传递参数的时候有一些不一样:
如下测试代码:
<html>
<head>
<script>
function demo(){
var text=escape("http://www.w3school.com.cn/My first/#qpp");
alert(text);
}
function demo1()
{
var test1="http://www.w3school.com.cn/My first/#qpp"
alert(encodeURIComponent(test1));
}
function demo3()
{
var test1="http://www.w3school.com.cn/My first/#qpp"
alert(decodeURI (test1));
}
function myapp(text)
{
var text=unescape(text);
alert(text);
}
</script>
</head>
<body>
<input type="button" onclick="demo()" value="escape"/><br>
<input type="button" onclick="demo3()" value="decodeURI"/><br>
<input type="button" onclick="demo1()" value="encodeURIComponent"/><br>
<input type="button" onclick="myapp('Visit%20W3School%21')" value="unescape"/><br>
</body>
</html>
测试截图如下:


以上为测试的截图,对于在查询字符串中需要# 等一下特殊字符的可以有帮助。
JavaScript decodeURI()与decodeURIComponent() 使用与区别的更多相关文章
- javascript中escape()、unescape()、encodeURI()、encodeURIComponent()、decodeURI()、decodeURIComponent()比较
这些URI方法encodeURI.encodeURIComponent().decodeURI().decodeURIComponent()代替了BOM的escape()和unescape()方法.U ...
- js解码编码decodeURI与decodeURIComponent区别
###decodeURI与decodeURIComponent区别 1. 概念: URI: Uniform ResourceIdentifiers,通用资源标识符 Global对象的encodeURI ...
- 一张图看懂encodeURI、encodeURIComponent、decodeURI、decodeURIComponent的区别
一.这四个方法的用处 1.用来编码和解码URI的 统一资源标识符,或叫做 URI,是用来标识互联网上的资源(例如,网页或文件)和怎样访问这些资源的传输协议(例如,HTTP 或 FTP)的字符串.除了e ...
- encodeURI、encodeURIComponent、decodeURI、decodeURIComponent的区别
一.这四个方法的用处 1.用来编码和解码URI的 统一资源标识符,或叫做 URI,是用来标识互联网上的资源(例如,网页或文件)和怎样访问这些资源的传输协议(例如,HTTP 或 FTP)的字符串.除了e ...
- decodeURI 与 decodeURIComponent 区别
1. 关于URL.encodeURI 及 encodeURIComponent: URI: Uniform Resource Identifiers,通用资源标识符 Global 对象的 encode ...
- decodeURI、decodeURIComponent 编码方法
——摘自<JavaScript高级程序设计> 编码: Global 对象的 encodeURI()和 encodeURIComponent()方法可以对 URI(Uniform Resou ...
- JS中encodeURI、encodeURIComponent、decodeURI、decodeURIComponent
js 对文字进行编码涉及2个函数:encodeURI,encodeURIComponent,相应2个解码函数:decodeURI,decodeURIComponent 1.用来编码和解码URI的 统一 ...
- 结合实例详细介绍encodeURI()、encodeURIComponent()、decodeURI()、decodeURIComponent()使用方法
在介绍encodeURI().encodeURIComponent().decodeURI().decodeURIComponent()方法前我们需要了解Global对象的概念: Global(全 ...
- JavaScript返回上一页代码区别
JavaScript返回上一页代码区别: window.history.go(-1); //返回上一页 window.history.back(); //返回上一页 //如果要强行刷新的话就是:win ...
随机推荐
- .net webform 把word转为html
首先添加引用 引用命名空间 using Microsoft.Office.Interop.Word; using System; using System.Collections.Generic; u ...
- 20145106 《Java程序设计》第1周学习总结
20145106 <Java程序设计>第1周学习总结 教材学习内容总结 因为我用的是Mac,所以教材内容暂时对我的编译java没有帮助.不过还好我也在同学和自己的帮助学习下初步学会了在Ma ...
- 《Java程序设计》第三章-基础语法
20145221<Java程序设计>第三章-基础语法 总结 教材学习内容总结 类型.变量与运算符 类型 Java可区分为基本类型(Primitive Type)和类类型(Class Typ ...
- /etc/rc.local 与 /etc/profile
1.用户自己源码安装的软件组要自启动,可以在/etc/rc.local中配置,rc.loacl 是rc.d/rc.local的一个软连接.rc.local -> rc.d/rc.local 2. ...
- python 输出环境变量
import os # Access all environment variables print('*---------------ENVIRON-------------------*') pr ...
- python 使用两个列表合成字典
keys = ['red', 'green', 'blue'] values = ['#FF0000','#008000', '#0000FF'] color_dictionary = dict(zi ...
- [OSG]OSG的相关扩展
参考:osg官网 http://www.osgchina.org/index.php?view=article&id=176 http://trac.openscenegraph.org/pr ...
- angular常用的服务
在 AngularJS 中,服务是一个函数或对象,可在你的 AngularJS 应用中使用. AngularJS 内建了30 多个服务. $window$routeProvider 1. $http服 ...
- 为什么要使用MQ消息中间件?它解决了什么问题?
1.应用场景 1.1 异步处理 场景说明:用户注册后,需要发注册邮件和注册短信,传统的做法有两种1.串行的方式;2.并行的方式 (1)串行方式:将注册信息写入数据库后,发送注册邮件,再发送注册短信,以 ...
- 不管服不服 Windows仍是全球第一大桌面系统
不管服不服 Windows仍是全球第一大桌面系统 近日,根据来自市场调研机构 Net Applications 公布的统计数据显示,Windows 依然是世界上排名第一的操作系统,而且未来将很难被打破 ...