JS中decodeURI()与decodeURIComponent()区别
来源:互联网 发布:阿里云服务器推荐 编辑:程序博客网 时间:2024/05/21 11:47
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 test = "http://www.test.com/My test/";
var test1 = encodeURI(test);
var test2 = decodeURI(test1);
var test3 = encodeURIComponent(test);
var test4 = decodeURIComponent(test3);
document.write(test1 + "<br />");
document.write(test2 + "<br />");
document.write(test3 + "<br />");
document.write(test4 + "<br />");
</script>
</body>
</html>
运行结果:
http://www.test.com/My%20test/
http://www.test.com/My test/
http%3A%2F%2Fwww.test.com%2FMy%20test%2F
http://www.test.com/My test/
-------------------------------------------------------------------------------------------------------------------------------------------
encodeURIComponent
将文本字符串编码为一个统一资源标识符 (URI) 的一个有效组件。
encodeURIComponent(encodedURIString)
必选的encodedURIString参数代表一个已编码的 URI 组件。
说明
encodeURIComponent方法返回一个已编码的 URI。如果您将编码结果传递给decodeURIComponent,那么将返回初始的字符串。因为encodeURIComponent方法对所有的字符编码,请注意,如果该字符串代表一个路径,例如/folder1/folder2/default.html,其中的斜杠也将被编码。这样一来,当该编码结果被作为请求发送到 web 服务器时将是无效的。如果字符串中包含不止一个 URI 组件,请使用encodeURI方法进行编码。
escape 方法
返回一个可在所有计算机上读取的编码 String 对象。
function escape(charString : String) : String
参数
charString
必选。要编码的任何 String 对象或文本。
备注
escape 方法返回一个包含 charstring 内容的字符串值(Unicode 格式)。所有空格、标点、重音符号以及任何其他非 ASCII 字符都用 %xx 编码替换,其中 xx 等于表示该字符的十六进制数。例如,空格返回为“ ”。
字符值大于 255 的字符以 %uxxxx 格式存储。
注意 escape 方法不能用来对“统一资源标识符”(URI) 进行编码。对其编码应使用 encodeURI 和 encodeURIComponent 方法。
要求
版本 1
请参见
encodeURI 方法 | encodeURIComponent 方法 | String 对象 | 方法
适用于:Global 对象
encodeURI 方法
返回编码为有效的统一资源标识符 (URI) 的字符串。
function encodeURI(URIString : String) : String
参数
URIString
必选。表示编码 URI 的字符串。
备注
encodeURI 方法返回一个已编码的 URI。如果将编码结果传递给 decodeURI,则将返回初始的字符串。encodeURI 不对下列字符进行编码:“:”、“/”、“;”和“?”。请使用 encodeURIComponent 对这些字符进行编码。
要求
版本 5.5
请参见
decodeURI 方法 | decodeURIComponent 方法
适用于:Global 对象
encodeURIComponent 方法
返回编码为统一资源标识符 (URI) 的有效组件的字符串。
function encodeURIComponent(encodedURIString : String) : String
参数
encodedURIString
必选。表示编码 URI 组件的字符串。
备注
encodeURIComponent 方法返回一个已编码的 URI。如果将编码结果传递给 decodeURIComponent,则将返回初始的字符串。因为 encodeURIComponent 方法将对所有字符编码,请注意,如果该字符串代表一个路径,例如 /folder1/folder2/default.html,则其中的斜杠也将被编码,这样,当该字符串作为请求发送到 Web 服务器时它将是无效的。如果字符串中包含多个 URI 组件,请使用 encodeURI 方法进行编码。
要求
版本 5.5
请参见
decodeURI 方法 | decodeURIComponent 方法
适用于:Global 对象
方法
从用 escape 方法编码的 String 对象中返回已解码的字符串。
function (charString : String) : String
参数
charString
必选。要解码的 String 对象或文本。
备注
方法返回一个包含 charstring 内容的字符串值。所有以 %xx 十六进制形式编码的字符都用 ASCII 字符集当中等效的字符代替。
以 %uxxxx 格式(Unicode 字符)编码的字符用十六进制编码 xxxx 的 Unicode 字符代替。
注意 方法不应用于解码“统一资源标识符”(URI)。请改用 decodeURI 和 decodeURIComponent 方法。
要求
版本 1
请参见
decodeURI 方法 | decodeURIComponent 方法 | escape 方法 | String 对象
适用于:Global 对象
decodeURI 方法
返回一个已编码的统一资源标识符 (URI) 的非编码形式。
function decodeURI(URIstring : String) : String
参数
URIstring
必选。表示编码 URI 的字符串。
备注
使用 decodeURI 方法代替已经过时的 方法。
decodeURI 方法返回一个字符串值。
如果 URIString 无效,将发生 URIError。
要求
版本 5.5
请参见
decodeURIComponent 方法 | encodeURI 方法
适用于:Global 对象
decodeURIComponent 方法
返回统一资源标识符 (URI) 的一个已编码组件的非编码形式。
function decodeURIComponent(encodedURIString : String) : String
必选的 encodedURIString 参数是一个表示已编码的 URI 组件的值。
备注
URIComponent 是一个完整的 URI 的一部分。
如果 encodedURIString 无效,则将产生 URIError。
要求
版本 5.5
请参见
decodeURI 方法 | encodeURI 方法
- JS中decodeURI()与decodeURIComponent()区别
- JS中decodeURI()与decodeURIComponent()区别
- JS中decodeURI()与decodeURIComponent()区别
- JS中decodeURI()与decodeURIComponent()区别
- JS中decodeURI()与decodeURIComponent()区别
- JS中decodeURI()与decodeURIComponent()区别
- JavaScript decodeURI()与decodeURIComponent()区别
- JavaScript decodeURI()与decodeURIComponent()区别
- encodeURI、decodeURI、encodeURIComponent与decodeURIComponent的区别
- java中URLEncoder、URLDecoder 与js中 en/decodeURI()、en/decodeURIComponent()使用
- js encodeURI() decodeURI() encodeURIComponent() decodeURIComponent()
- JS----编码,解码decodeURIComponent,encodeURIComponent,decodeURI,encodeURI
- escape()、encodeURI()、decodeURI()、encodeURIComponent()、decodeURIComponent()区别详解
- js中的编码解码--escape/unescape、encodeURI/decodeURI 、encodeURIComponent/decodeURIComponent
- 一张图看懂encodeURI、encodeURIComponent、decodeURI、decodeURIComponent的区别
- 一张图看懂encodeURI、encodeURIComponent、decodeURI、decodeURIComponent的区别
- unescape decodeURI decodeURIComponent
- unescape,decodeURI,decodeURIComponent
- Win8.1激活方法
- QTcpSocker, QTcpServer
- JavaScript的问题总结
- Javascript的console.log()用法
- Console命令详解,让调试js代码变得更简单
- JS中decodeURI()与decodeURIComponent()区别
- EL表达式的常用方式
- 关于sql server的卸载
- 【js】netzgesta网站
- event.keycode值大全
- 设置Eclipse/MyEclipse中编辑界面点击任何文件后Package Explorer导航自动定位该文件
- 用javascript 禁止右键,禁止复制,禁止粘贴
- 你可能不知道的10个JavaScript小技巧 .
- javascript数组操作大全