日期:2014-05-16  浏览次数:20413 次

JS中decodeURI()与decodeURIComponent()区别

JS中decodeURI()与decodeURIComponent()区别

摘要: 本文章就是介绍两个解码的函数,他们就是decodeURI()和decodeURIComponent()函数,这两个函数可以对特定函数生成的密码字符串进行解密操作,就可以生成为未解密的字符串,比较实用,下面
本文章就是介绍两个解码的函数,他们就是decodeURI()和decodeURIComponent()函数,这两个函数可以对特定函数生成的密码字符串进行解密操作,就可以生成为未解密的字符串,比较实用,下面来看看这两个函数的用法和实例,你就会用了:

decodeURI()定义和用法:decodeURI() 函数可对 encodeURI() 函数编码过的URI 进行解码。

语法:decodeURI(URIstring)

参数 描述:URIstring 必需。一个字符串,含有要解码的 URI 或其他要解码的文本。

返回值:URIstring 的副本,其中的十六进制转义序列将被它们表示的字符替换。

?

decodeURIComponent()定义和用法:decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码。

语法:decodeURIComponent(URIstring)

参数 描述:URIstring 必需。一个字符串,含有编码 URI 组件或其他要解码的文本。

返回值:URIstring 的副本,其中的十六进制转义序列将被它们表示的字符替换。

实例:

<html>
<body>

<script type="text/javascript">

var test1="http://www.wljcz.com/My first/";
var nn=encodeURI(test1);
var now=decodeURI(test1);
document.write(nn+ "<br />");
document.write(now);

var test1="http://www.wljcz.com/My first/";
var bb=encodeURIComponent(test1);
var nnow=decodeURIComponent(bb);
document.write(bb+ "<br />");
document.write(nnow);

</script>

</body>
</html>

其运行结果为:

http://www.wljcz.com/My%20first/
http://www.wljcz.com/My first/

http%3A%2F%2Fwww.wljcz.com%2FMy%20first%2F
http://www.wljcz.com/My first/

?

?