encodeURIComponent 和 decodeURIComponent

作者: 来源:MSDN 日期:2007-1-29

encodeURIComponent 方法 

返回编码为统一资源标识符 (URI) 的有效组件的字符串。

function encodeURIComponent(encodedURIString : String) : String
参数
encodedURIString

必选。表示编码 URI 组件的字符串。

备注

encodeURIComponent 方法返回一个已编码的 URI。如果将编码结果传递给 decodeURIComponent,则将返回初始的字符串。因为 encodeURIComponent 方法编码所有字符,所以请注意该字符串是否表示路径,例如 /folder1/folder2/default.html。斜杠字符将被编码,因此如果作为请求发送到 Web 服务器将无效。如果字符串中包含多个 URI 组件,请使用 encodeURI 方法进行编码。


decodeURIComponent 方法

返回统一资源标识符 (URI) 的一个已编码组件的非编码形式。

function decodeURIComponent(encodedURIString : String) : String
参数

必选的 encodedURIString 参数是一个表示已编码的 URI 组件的值。

备注

URIComponent 是一个完整的 URI 的一部分。

如果 encodedURIString 无效,则将产生 URIError。

相关文章