码迷,mamicode.com
首页 > Web开发 > 详细

js中decodeURI()和encodeURI()区别,decodeURIComponent和encodeURIComponent区别

时间:2017-07-27 18:25:55      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:test   传递参数   副本   转义   nbsp   十六   dem   函数   替换   

decodeURI()定义和用法:decodeURI()函数可对encodeURI()函数编码过的URI进行解码.
语法:decodeURI(URIstring)
参数描述:URIstring必需,一个字符串,含有要解码的URI组或其他要解码的文本.
返回值:URIstring的副本,其中的十六进制转义序列将被它们表示的字符替换.

decodeURIComponent()定义和用法:decodeURIComponent()函数可对encodeURIComponent()函数编码过的URI进行解码.
语法:decodeURIComponent(URIstring)
参数描述:URIstring必需,一个字符串,含有解码的URI组件或其他要解码的文本.
返回值:URIstring的副本,其中的十六进制转义序列将被它们表示的字符替换.

以上是对于用法的说明,但是在实际的使用过程中有一下问题:

#特殊符号进行进行编码传递参数的时候有一些不一样:

如下测试代码:

<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);
} 

 

js中decodeURI()和encodeURI()区别,decodeURIComponent和encodeURIComponent区别

标签:test   传递参数   副本   转义   nbsp   十六   dem   函数   替换   

原文地址:http://www.cnblogs.com/circleone/p/7245878.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!